Book description
Create web services that are lightweight, maintainable, scalable, and secure using the best tools and techniques designed for Python
About This Book
Develop RESTful Web Services using the most popular frameworks in Python
Configure and fine-tune your APIs using the best tools and techniques available
This practical guide will help you to implement complete REST-based APIs from scratch
Who This Book Is For
This book is for web developers who have working knowledge of Python and would like to build amazing web services by taking advantage of the various frameworks of Python. You should have some knowledge of RESTful APIs.
What You Will Learn
Develop complex RESTful APIs from scratch with Python combined with and without data sources
Choose the most appropriate (micro) framework based on the specific requirements of a RESTful API / web service
Debug, test, and profile RESTful APIs with each of the frameworks
Develop a complex RESTful API that interacts with a PostgreSQL database
Add authentication and permissions to a RESTful API built in each of the frameworks
Map URL patterns to request handlers and check how the API works
Profile an existing API and refactor it to take advantage of asynchronous code
In Detail
Python is the language of choice for millions of developers worldwide, due to its gentle learning curve as well as its vast applications in day-to-day programming. It serves the purpose of building great web services in the RESTful architecture. This book will show you the best tools you can use to build your own web services.
Learn how to develop RESTful APIs using the popular Python frameworks and all the necessary stacks with Python, Django, Flask, and Tornado, combined with related libraries and tools. We will dive deep into each of these frameworks to build various web services, and will provide use cases and best practices on when to use a particular framework to get the best results.
We will show you everything required to successfully develop RESTful APIs with the four frameworks such as request handling, URL mapping, serialization, validation, authentication, authorization, versioning, ORMs, databases, custom code for models and views, and asynchronous callbacks. At the end of each framework, we will add authentication and security to the RESTful APIs and prepare tests for it.
By the end of the book, you will have a deep understanding of the stacks needed to build RESTful web services.
Style and approach
The book takes a straightforward approach, not spending time getting you started with RESTful APIs and web services. It will give you the best use cases for each framework to build great web services in Python.
Table of contents
-
Building RESTful Python Web Services
- Building RESTful Python Web Services
- Credits
- About the Author
- Acknowledgments
- About the Reviewer
- www.PacktPub.com
- Preface
-
1. Developing RESTful APIs with Django
- Designing a RESTful API to interact with a simple SQLite database
- Understanding the tasks performed by each HTTP method
- Working with lightweight virtual environments
- Setting up the virtual environment with Django REST framework
- Creating the models
- Managing serialization and deserialization
- Writing API views
- Making HTTP requests to the API
- Test your knowledge
- Summary
-
2. Working with Class-Based Views and Hyperlinked APIs in Django
- Using model serializers to eliminate duplicate code
- Working with wrappers to write API views
- Using the default parsing and rendering options and move beyond JSON
- Browsing the API
- Designing a RESTful API to interact with a complex PostgreSQL database
- Understanding the tasks performed by each HTTP method
- Declaring relationships with the models
- Managing serialization and deserialization with relationships and hyperlinks
- Creating class-based views and using generic classes
- Taking advantage of generic class based views
- Working with endpoints for the API
- Creating and retrieving related resources
- Test your knowledge
- Summary
-
3. Improving and Adding Authentication to an API With Django
- Adding unique constraints to the models
- Updating a single field for a resource with the PATCH method
- Taking advantage of pagination
- Customizing pagination classes
- Understanding authentication, permissions and throttling
- Adding security-related data to the models
- Creating a customized permission class for object-level permissions
- Persisting the user that makes a request
- Configuring permission policies
- Setting a default value for a new required field in migrations
- Composing requests with the necessary authentication
- Browsing the API with authentication credentials
- Test your knowledge
- Summary
-
4. Throttling, Filtering, Testing, and Deploying an API with Django
- Understanding throttling classes
- Configuring throttling policies
- Testing throttling policies
- Understanding filtering, searching, and ordering classes
- Configuring filtering, searching, and ordering for views
- Testing filtering, searching, and ordering
- Filtering, searching, and ordering in the Browsable API
- Setting up unit tests
- Writing a first round of unit tests
- Running unit tests and checking testing coverage
- Improving testing coverage
- Understanding strategies for deployments and scalability
- Test your knowledge
- Summary
-
5. Developing RESTful APIs with Flask
- Designing a RESTful API to interact with a simple data source
- Understanding the tasks performed by each HTTP method
- Setting up a virtual environment with Flask and Flask-RESTful
- Declaring status codes for the responses
- Creating the model
- Using a dictionary as a repository
- Configuring output fields
- Working with resourceful routing on top of Flask pluggable views
- Configuring resource routing and endpoints
- Making HTTP requests to the Flask API
- Test your knowledge
- Summary
-
6. Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask
- Designing a RESTful API to interact with a PostgreSQL database
- Understanding the tasks performed by each HTTP method
- Installing packages to simplify our common tasks
- Creating and configuring the database
- Creating models with their relationships
- Creating schemas to validate, serialize, and deserialize models
- Combining blueprints with resourceful routing
- Registering the blueprint and running migrations
- Creating and retrieving related resources
- Test your knowledge
- Summary
-
7. Improving and Adding Authentication to an API with Flask
- Improving unique constraints in the models
- Updating fields for a resource with the PATCH method
- Coding a generic pagination class
- Adding pagination features
- Understanding the steps to add authentication and permissions
- Adding a user model
- Creating a schemas to validate, serialize, and deserialize users
- Adding authentication to resources
- Creating resource classes to handle users
- Running migrations to generate the user table
- Composing requests with the necessary authentication
- Test your knowledge
- Summary
- 8. Testing and Deploying an API with Flask
-
9. Developing RESTful APIs with Tornado
- Designing a RESTful API to interact with slow sensors and actuators
- Understanding the tasks performed by each HTTP method
- Setting up a virtual environment with Tornado
- Declaring status codes for the responses
- Creating the classes that represent a drone
- Writing request handlers
- Mapping URL patterns to request handlers
- Making HTTP requests to the Tornado API
- Test your knowledge
- Summary
-
10. Working with Asynchronous Code, Testing, and Deploying an API with Tornado
- Understanding synchronous and asynchronous execution
- Refactoring code to take advantage of asynchronous decorators
- Mapping URL patterns to asynchronous request handlers
- Making HTTP requests to the Tornado non-blocking API
- Setting up unit tests
- Writing a first round of unit tests
- Running unit tests with nose2 and checking testing coverage
- Improving testing coverage
- Other Python Web frameworks for building RESTful APIs
- Test your knowledge
- Summary
-
11. Exercise Answers
- Chapter 1, Developing RESTful APIs with Django
- Chapter 2, Working with Class-Based Views and Hyperlinked APIs in Django
- Chapter 3, Improving and Adding Authentication to an API With Django
- Chapter 4, Throttling, Filtering, Testing, and Deploying an API with Django
- Chapter 5, Developing RESTful APIs with Flask
- Chapter 6, Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask
- Chapter 7, Improving and Adding Authentication to an API with Flask
- Chapter 8, Testing and Deploying an API with Flask
- Chapter 9, Developing RESTful APIs with Tornado
- Chapter 10, Working with Asynchronous Code, Testing, and Deploying an API with Tornado
Product information
- Title: Building RESTful Python Web Services
- Author(s):
- Release date: October 2016
- Publisher(s): Packt Publishing
- ISBN: 9781786462251
You might also like
book
Building Web Applications with Python and Neo4j
Develop exciting real-world Python-based web applications with Neo4j using frameworks such as Flask, Py2neo, and Django …
book
Django RESTful Web Services
Design, build and test RESTful web services with the Django framework and Python About This Book …
book
Building Web Applications with Flask
Use Python and Flask to build amazing web applications, just the way you want them! Learn …
book
Building RESTful Web services with Go
Explore the necessary concepts of REST API development by building few real world services from scratch. …