Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building RESTful Python Web Services

You're reading from  Building RESTful Python Web Services

Product type Book
Published in Oct 2016
Publisher Packt
ISBN-13 9781786462251
Pages 418 pages
Edition 1st Edition
Languages
Author (1):
Gaston C. Hillar Gaston C. Hillar
Profile icon Gaston C. Hillar

Table of Contents (18) Chapters

Building RESTful Python Web Services
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
1. Developing RESTful APIs with Django 2. Working with Class-Based Views and Hyperlinked APIs in Django 3. Improving and Adding Authentication to an API With Django 4. Throttling, Filtering, Testing, and Deploying an API with Django 5. Developing RESTful APIs with Flask 6. Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask 7. Improving and Adding Authentication to an API with Flask 8. Testing and Deploying an API with Flask 9. Developing RESTful APIs with Tornado 10. Working with Asynchronous Code, Testing, and Deploying an API with Tornado 11. Exercise Answers

Configuring resource routing and endpoints


We must make the necessary resource routing configurations to call the appropriate methods and pass them all the necessary arguments by defining URL rules. The following lines create the main entry point for the application, initialize it with a Flask application and configure the resource routing for the api. Open the previously created api/api.py file and add the following lines. The code file for the sample is included in the restful_python_chapter_05_01 folder:

app = Flask(__name__) 
api = Api(app) 
api.add_resource(MessageList, '/api/messages/') 
api.add_resource(Message, '/api/messages/<int:id>', endpoint='message_endpoint') 
 
 
if __name__ == '__main__': 
    app.run(debug=True) 

The code creates an instance of the flask_restful.Api class and saves it in the api variable. Each call to the api.add_resource method routes a URL to a resource, specifically to one of the previously declared subclasses of the flask_restful.Resource class...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}