Python is the language of choice for millions of developers worldwide, due to its gentle learning curve and its vast applications in day-to-day programming. It builds great and reliable web services in the RESTful architecture. This video will show you the best tools you can use to build your own Python web services.
You’ll start by learning how to develop RESTful APIs using the Django framework combined with related libraries and tools. We’ll delve into the Django framework to build various web services. We’ll show you everything you need to successfully develop RESTful APIs with the Django framework such as request handling, URL mapping, serialization, validation, authentication, authorization, and databases.
By the end of the video, you’ll have a deep understanding of the stacks needed to build RESTful web services.
About the author
Gastón C. Hillar is Italian and has been working with computers since he was eight. He began programming with the legendary Texas TI-99/4A and Commodore 64 home computers in the early 80s. He has a Bachelor's degree in Computer Science (he graduated with honors) and an MBA (he graduated with an outstanding thesis). At present, Gastón is an independent IT consultant and freelance author who is always looking for new adventures around the world.
He has been a senior contributing editor at Dr. Dobb's and has written more than a hundred articles on software development topics. Gastón was also a former Microsoft MVP in technical computing. He has received the prestigious Intel® Black Belt Software Developer award eight times.
In this video, we will work with a very simple SQLite database to make the default database for a new Django REST framework project.
In this video, we will work with the lightweight virtual environments introduced in Python 3.3 and improved in Python 3.4.
We will install and set up the Django web framework.
In this video, we will create a simple game model that we will use to represent and persist games.
In this video, we will create a serializer class for the game instances to manage serialization and deserialization from JSON.
In this video, we will create Django views to return JSON representations for each HTTP request that our API will handle.
In this video, we will compose and send HTTP requests locally in our development computer or devices connected to our LAN.
In this video, we will work with GUI (Graphical User Interface) tools to easily compose and send HTTP requests.
In this video, we will declare many attributes with the same names that we used in the game model.
In this video, we will use a consistent API to provide an accurate response for a game resource or the games collection.
In this video, we will specify the default settings for each view in the gamesapi.
In this video, we will use the default content renderers configured in Django REST Framework.
In this video, we will interact with a complex database model to register player scores into game categories and will understand the HTTP verbs and scope for our new API.
We will create the models that we will use to represent and persist the game categories, games, players and scores, and their relationships.
RESTful Web API has to be able to serialize and deserialize the GameCategory,Game, Player, and PlayerScore instances into JSON representation.
We write API views by declaring class-based views, instead of function based views. We use base classes for our class based views to reduce the required code to the minimum and take advantage of the behaviour that has been generalized in Django REST Framework.
We create an endpoint for the root of our API to make it easier to browse the API with the browsable API feature and understand how everything works.
We will use the HTTPie command or its curl equivalents to compose and send HTTP requests to the API. You can perform the same tasks with your favorite GUI-based tool or with the browsable API.
We will make the necessary changes to the Game Category model to add a unique constraint on the name field. We will also add a unique constraint on the name field for the Game and Player models. In this video, we will learn the necessary steps to make changes to the constraints for many models and reflect the changes in the underlying database through migrations.
Pagination features available in Django REST Framework make it easy to specify how we want large result sets to be split into individual pages of data.
We are providing a paginated response that declares a max_limit class attribute that defaults to None. This attribute allows us to indicate the maximum allowable limit that can be specified using the limit query parameter.
Django REST Framework allows us to easily use different authentication schemes to identify the user that originated the request or the token that signed the request. Then, we use these credentials to apply the permission and throttling policies that will determine whether the request must be permitted or not.
The authenticated users will be able to create new games. Only the creator of a game will be able to update or delete it. All the requests that aren't authenticated will only have read-only access to games.
We will use the new permission class to ensure that only the game owners can make changes to an existing game. We will combine the first permission class with the second permission class that only allows read-only access to resources when the request is not authenticated as a user.
In this video, we will configure permission policies for the class-based views related to games.
In this video, we will compose and send an HTTP request to create a new game with authentication credentials, that is, with the superuser name and their password.
In this video, browsable API will compose and send a GET request display the results of its execution, that is, the API Root.
So far, we haven't established any limits on the usage of our API and therefore both authenticated and unauthenticated users can compose and send as many requests as they want to. However, any user can compose and send thousands of requests to be processed without any kind of limitation.
Now, we can launch Django's development server to compose and send HTTP requests.
We took advantage of the pagination features available in Django REST Framework to specify how we wanted large result sets to be split into individual pages of data. However, we have always been working with the entire queryset as the result set. Django REST Framework makes it easy to customize the filtering, searching, and sorting capabilities to the views we have already coded.
Let’s take a look at how to work with the filter_fields, search_fields, and ordering_fields attributes.
Now that we know the Configuring filtering, we will explore testing filtering in this video.
Let’s begin this section by making the necessary configurations to use the django_nose.NoseTestRunnerclass to run all the tests we code. We will use the necessary configurations to improve the accuracy of the test coverage measurements.
Now, we will define the first round of unit tests. Specifically, we will define unit tests related to the game category class based views: GameCategoryList and GameCategoryDetail.
We have now defined the first round of unit tests. Let’s run the unit tests in this video.
Let’s define additional unit tests to improve the testing coverage. Specifically, we will define unit tests related to the player class based views: PlayerList and PlayerDetail.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.