Book description
Explore the best tools and techniques to create lightweight, maintainable, and scalable Python web services
Key Features
- Combine Python with different data sources to build complex RESTful APIs from scratch
- Configure and fine-tune your APIs using the best tools and techniques available
- Use command-line and GUI tools to test CRUD operations performed by RESTful Web Services or APIs
Book Description
Python is the language of choice for millions of developers worldwide that builds great web services in RESTful architecture. This second edition of Hands-On RESTful Python Web Services will cover the best tools you can use to build engaging web services.
This book shows you how to develop RESTful APIs using the most popular Python frameworks and all the necessary stacks with Python, combined with related libraries and tools. You'll learn to incorporate all new features of Python 3.7, Flask 1.0.2, Django 2.1, Tornado 5.1, and also a new framework, Pyramid. As you advance through the chapters, you will get to grips with each of these frameworks to build various web services, and be shown use cases and best practices covering when to use a particular framework.
You'll then successfully develop RESTful APIs with all frameworks and understand how each framework processes HTTP requests and routes URLs. You'll also discover best practices for validation, serialization, and deserialization. In the concluding chapters, you will take advantage of specific features available in certain frameworks such as integrated ORMs, built-in authorization and authentication, and work with asynchronous code. At the end of each framework, you will write tests for RESTful APIs and improve code coverage.
By the end of the book, you will have gained a deep understanding of the stacks needed to build RESTful web services.
What you will learn
- Select the most appropriate framework based on requirements
- Develop complex RESTful APIs from scratch using Python
- Use requests handlers, URL patterns, serialization, and validations
- Add authentication, authorization, and interaction with ORMs and databases
- Debug, test, and improve RESTful APIs with four frameworks
- Design RESTful APIs with frameworks and create automated tests
Who this book is for
This book is for web developers who have a 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.
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- About Packt
- Contributors
- Preface
-
Developing RESTful APIs and Microservices with Flask 1.0.2
- Designing a RESTful API to interact with a simple data source
- Understanding the tasks performed by each HTTP method
- Understanding microservices
- Working with lightweight virtual environments
- Setting up a virtual environment with Flask and Flask-RESTful
- Declaring status codes for the responses with an enumerable
- 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
-
Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask
- Designing a RESTful API to interact with a PostgreSQL 10.5 database
- Understanding the tasks performed by each HTTP method
- Installing packages with the requirements.txt file to simplify our common tasks
- Creating the database
- Configuring the database
- Creating models with their relationships
- Creating schemas to validate, serialize, and deserialize models
- Combining blueprints with resourceful routing
- Understanding and configuring resourceful routing
- Registering the blueprint and running migrations
- Verifying the contents of the PostgreSQL database
- Creating and retrieving related resources
- Test your knowledge
- Summary
-
Improving Our API and Adding Authentication to it with Flask
- Improving unique constraints in the models
- Understanding the differences between the PUT and the PATCH methods
- 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 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
-
Testing and Deploying an API in a Microservice with Flask
- Setting up unit tests with pytest
- Creating a database for testing
- Creating fixtures to perform setup and teardown tasks for running clean tests
- Writing the first round of unit tests
- Running unit tests with pytest and checking testing coverage
- Improving testing coverage
- Understanding strategies for deployments and scalability
- Test your knowledge
- Summary
-
Developing RESTful APIs with Django 2.1
- Designing a RESTful API to interact with a simple SQLite database
- Understanding the tasks performed by each HTTP method
- Setting up the virtual environment with Django REST framework
- Creating the models
- Managing serialization and deserialization
- Understanding status codes for the responses
- Writing API views
- Making HTTP requests to the Django API
- Test your knowledge
- Summary
-
Working with Class-Based Views and Hyperlinked APIs in Django 2.1
- Using model serializers to eliminate duplicate code
- Working with wrappers to write API views
- Using the default parsing and rendering options and moving beyond JSON
- Browsing the API
- Designing a RESTful API to interact with a complex PostgreSQL 10.5 database
- Understanding the tasks performed by each HTTP method
- Declaring relationships with the models
- Installing packages with the requirements.txt file to work with PostgreSQL
- Configuring the database
- Running migrations
- Verifying the contents of the PostgreSQL database
- 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
- Browsing an API with relationships
- Creating and retrieving related resources
- Test your knowledge
- Summary
-
Improving Our API and Adding Authentication to it 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 and 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
-
Throttling, Filtering, Testing, and Deploying an API with Django 2.1
- Installing packages with the requirements.txt file to work with filters, throttling, and tests
- Understanding filtering, searching, and ordering classes
- Configuring filtering, searching, and ordering for views
- Executing HTTP requests to test filtering, searching, and ordering
- Filtering, searching and ordering in the Browsable API
- Understanding throttling classes and goals
- Configuring throttling policies
- Executing HTTP requests to test throttling policies
- Setting up unit tests with pytest
- Writing the first round of unit tests
- Running unit tests with pytest
- Improving testing coverage
- Running Django RESTful APIs on the cloud
- Test your knowledge
- Summary
-
Developing RESTful APIs with Pyramid 1.10
- Designing a RESTful API to interact with a simple data source
- Setting up the virtual environment with Pyramid 1.10
- Creating a new Pyramid project based on a template
- Creating the model
- Using a dictionary as a repository
- Creating a Marshmallow schema to validate, serialize, and deserialize the model
- Working with view callables and view configurations
- Understanding and configuring view handlers
- Making HTTP requests to the API with command-line tools
- Test your knowledge
- Summary
-
Developing RESTful APIs with Tornado 5.1.1
- 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 5.1.1
- Creating 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
-
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 with pytest
- Writing the first round of unit tests
- Running unit tests with pytest and checking testing coverage
- Improving testing coverage
- Understanding strategies for deploying Tornado APIs to the cloud
- Test your knowledge
- Summary
- Assessment
- Other Books You May Enjoy
Product information
- Title: Hands-On RESTful Python Web Services - Second Edition
- Author(s):
- Release date: December 2018
- Publisher(s): Packt Publishing
- ISBN: 9781789532227
You might also like
book
Building RESTful Python Web Services
Create web services that are lightweight, maintainable, scalable, and secure using the best tools and techniques …
book
Python Microservices Development
A practical approach to conquering the complexities of Microservices using the Python tooling ecosystem Key Features …
book
Hands-on JavaScript for Python Developers
Build robust full-stack web applications using two of the world's most popular programming languages Python and …
book
Hands-On Docker for Microservices with Python
A step-by-step guide to building microservices using Python and Docker, along with managing and orchestrating them …