▶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.
▶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
▶Key Features
⦁ 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.
▶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.
▶What this book covers
⦁ Chapter 1, Developing RESTful APIs with Django, in this chapter we will start working with Django and Django REST Framework, and we will create a RESTful Web API that performs CRUD (Create, Read, Update and Delete) operations on a simple SQLite database.
⦁ Chapter 2, Working with Class-Based Views and Hyperlinked APIs in Django, in this chapter we will expand the capabilities of the RESTful API that we started in the previous chapter. We will change the ORM settings to work with a more powerful PostgreSQL database and we will take advantage of advanced features included in Django REST Framework that allow us to reduce boilerplate code for complex APIs, such as class based views.
⦁ Chapter 3, Improving and Adding Authentication to an API with Django, in this chapter we will improve the RESTful API that we started in the previous chapter. We will add unique constraints to the model and update the database. We will make it easy to update single fields with the PATCH method and we will take advantage of pagination. We will start working with authentication, permissions and throttling.
⦁ Chapter 4, Throttling, Filtering, Testing and Deploying an API with Django, in this chapter we will take advantage of many features included in Django REST Framework to define throttling policies. We will use filtering, searching and ordering classes to make it easy to configure filters, search queries and desired order for the results in HTTP requests. We will use the browsable API feature to test these new features included in our API. We will write a first round of unit tests, measure test coverage and then write additional unit tests to improve test coverage. Finally, we will learn many considerations for deployment and scalability.
⦁ Chapter 5, Developing RESTful APIs with Flask, in this chapter we will start working with Flask and its Flask-RESTful extension. We will create a RESTful Web API that performs CRUD operations on a simple list.
⦁ Chapter 6, Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask, in this chapter we will expand the capabilities of the RESTful API that we started in the previous chapter. We will use SQLAlchemy as our ORM to work with a PostgreSQL database and we will take advantage of advanced features included in Flask and Flask-RESTful that will allow us to easily organize code for complex APIs, such as models and blueprints.
⦁ Chapter 7, Improving and Adding Authentication to an API with Flask, in this chapter we will improve the RESTful API in many ways. We will add user friendly error messages when resources aren’t unique. We will test how to update single or multiple fields with the PATCH method and we will create our own generic pagination class. Then, we will start working with authentication and permissions. We will added a user model and we will update the database. We will make many changes in the different pieces of code to achieve a specific security goal and we will take advantage of Flask-HTTPAuth and passlib to use HTTP authentication in our API.
⦁ Chapter 8, Testing and Deploying an API with Flask, in this chapter we will set up a testing environment. We will install nose2 to make it easy to discover and execute unit tests and we will create a new database to be used for testing. We will write a first round of unit tests, measure test coverage and then write additional unit tests to improve test coverage. Finally, we will learn many considerations for deployment and scalability.
⦁ Chapter 9, Developing RESTful APIs with Tornado, we will work with Tornado to create a RESTful Web API. We will design a RESTful API to interact with slow sensors and actuators. We will defined the requirements for our API and we will understand the tasks performed by each HTTP method. We will create the classes that represent a drone and write code to simulate slow I/O operations that are called for each HTTP request method. We will write classes that represent request handlers and process the different HTTP requests and configure the URL patterns to route URLs to request handlers and their methods.
⦁ Chapter 10, Working with Asynchronous Code, Testing, and Deploying an API with Tornado, in this chapter we will understand the difference between synchronous and asynchronous execution. We will create a new version of the RESTful API that takes advantage of the nonblocking features in Tornado combined with asynchronous execution. We will improve scalability for our existing API and we will make it possible to start executing other requests while waiting for the slow I/O operations with sensors and actuators. Then, we will set up a testing environment. We will install nose2 to make it easy to discover and execute unit tests. We will wrote a first round of unit tests, measure test coverage and then write additional unit tests to improve test coverage. We will create all the necessary tests to have a complete coverage of all the lines of code.