Building RESTful Python Web Services

Create web services that are lightweight, maintainable, scalable, and secure using the best tools and techniques designed for Python
Preview in Mapt

Building RESTful Python Web Services

Gastón C. Hillar

4 customer reviews
Create web services that are lightweight, maintainable, scalable, and secure using the best tools and techniques designed for Python
Mapt Subscription
FREE
$29.99/m after trial
eBook
$28.00
RRP $39.99
Save 29%
Print + eBook
$49.99
RRP $49.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$28.00
$49.99
$29.99 p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


Building RESTful Python Web Services Book Cover
Building RESTful Python Web Services
$ 39.99
$ 28.00
Building RESTful Web services with Go Book Cover
Building RESTful Web services with Go
$ 31.99
$ 22.40
Buy 2 for $35.00
Save $36.98
Add to Cart

Book Details

ISBN 139781786462251
Paperback418 pages

Book Description

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.

Table of Contents

Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 8: Testing and Deploying an API with Flask
Setting up unit tests
Writing a first round of unit tests
Running unit tests with nose2 and checking testing coverage
Improving testing coverage
Understanding strategies for deployments and scalability
Test your knowledge
Summary
Chapter 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
Chapter 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
Chapter 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

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

Authors

Table of Contents

Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 8: Testing and Deploying an API with Flask
Setting up unit tests
Writing a first round of unit tests
Running unit tests with nose2 and checking testing coverage
Improving testing coverage
Understanding strategies for deployments and scalability
Test your knowledge
Summary
Chapter 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
Chapter 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
Chapter 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

Book Details

ISBN 139781786462251
Paperback418 pages
Read More
From 4 reviews

Read More Reviews

Recommended for You

Modern Python Cookbook Book Cover
Modern Python Cookbook
$ 39.99
$ 28.00
Mastering Object-oriented Python Book Cover
Mastering Object-oriented Python
$ 26.99
$ 18.90
Mastering Python Book Cover
Mastering Python
$ 31.99
$ 22.40
Django: Web Development with Python Book Cover
Django: Web Development with Python
$ 67.99
$ 47.60
Python: Journey from Novice to Expert Book Cover
Python: Journey from Novice to Expert
$ 69.99
$ 49.00
Mastering Django: Core Book Cover
Mastering Django: Core
$ 39.99
$ 28.00