Django RESTful Web Services
Gaston C. Hillar, Norbert Máté
- 326 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Django RESTful Web Services
Gaston C. Hillar, Norbert Máté
About This Book
Design, build and test RESTful web services with the Django framework and Python
Key Features
- Create efficient real-world RESTful web services with the latest Django framework
- Authenticate, secure, and integrate third-party packages efficiently in your Web Services
- Leverage the power of Python for faster Web Service development
Book Description
Django is a Python web framework that makes the web development process very easy. It reduces the amount of trivial code, which simplifies the creation of web applications and results in faster development. It is very powerful and a great choice for creating RESTful web services.
If you are a Python developer and want to efficiently create RESTful web services with Django for your apps, then this is the right book for you.
The book starts off by showing you how to install and configure the environment, required software, and tools to create RESTful web services with Django and the Django REST framework. We then move on to working with advanced serialization and migrations to interact with SQLite and non-SQL data sources. We will use the features included in the Django REST framework to improve our simple web service.
Further, we will create API views to process diverse HTTP requests on objects, go through relationships and hyperlinked API management, and then discover the necessary steps to include security and permissions related to data models and APIs. We will also apply throttling rules and run tests to check that versioning works as expected. Next we will run automated tests to improve code coverage.
By the end of the book, you will be able to build RESTful web services with Django.
What you will learn
- The best way to build a RESTful Web Service or API with Django and the Django REST Framework
- Develop complex RESTful APIs from scratch with Django and the Django REST Framework
- Work with either SQL or NoSQL data sources
- Design RESTful Web Services based on application requirements
- Use third-party packages and extensions to perform common tasks
- Create automated tests for RESTful web services
- Debug, test, and profile RESTful web services with Django and the Django REST Framework
Who this book is for
This book is for Python developers who want to create RESTful web services with Django; you need to have a basic working knowledge of Django but no previous experience with RESTful web services is required.
Frequently asked questions
Information
Working with Advanced Relationships and Serialization
- Defining the requirements for a complex RESTful Web Service
- Creating a new app with Django
- Configuring a new web service
- Defining many-to-one relationships with models.ForeignKey
- Installing PostgreSQL
- Running migrations that generate relationships
- Analyzing the database
- Configuring serialization and deserialization with relationships
- Defining hyperlinks with serializers.HyperlinkedModelSerializer
- Working with class-based views
- Taking advantage of generic classes and generic views
- Generalizing and mixing behavior
- Working with routing and endpoints
- Making requests that interact with resources that have relationships
Defining the requirements for a complex RESTful Web Service
- Drone categories (DroneCategory model)
- Drones (Drone model)
- Pilots (Pilot model)
- Competitions (Competition model)
- A foreign key to a drone category (DroneCategory model)
- A name
- A manufacturing date
- A bool value indicating whether the drone participated in at least one competition or not
- A timestamp with the date and time in which the drone was inserted in the database
- A name
- A gender value
- An integer value with the number of races in which the pilot participated
- A timestamp with the date and time in which the pilot was inserted in the database
- A foreign key to a pilot (Pilot model)
- A foreign key to a drone (Drone model)
- A distance value (measured in feet)
- A date in which the drone controlled by the pilot reached the specified distance value
HTTP verb | Scope | Semantics |
GET | Drone category | Retrieve a single drone category. The drone category must include a list of URLs for each drone resource that belongs to the drone category. |
GET | Collection of drone categories | Retrieve all the stored drone categories in the collection, sorted by their name in ascending order. Each drone category must include a list of URLs for each drone resource that belongs to the drone category. |
POST | Collection of drone categories | Create a new drone category in the collection. |
PUT | Drone category | Update an existing drone category. |
PATCH | Drone category | Update one or more fields of an existing drone category. |
DELETE | Drone category | Delete an existing drone category. |
GET | Drone | Retrieve a single drone. The drone must include its drone category description. |
GET | Collection of drones | Retrieve all the stored drones in the collection, sorted by their name in ascending order. Each drone must include its drone category description. |
POST | Collection of drones | Create a new drone in the collection. |
PUT | Drone | Update an existing drone. |
PATCH | Drone | Update one or more fields of an existing drone. |
DELETE | Drone | Delete an existing drone. |
GET | Pilot | Retrieve a single pilot. The pilot must include a list of the registered competitions, sorted by distance in descending order. The list must include all the details for the competition in which the pilots and his related drone participated. |
GET | Collection of pilots | Retrieve all the stored pilots in the collection, sorted by their name in ascending order. Each pilot must include a list of the registered competitions, sorted by distance in descending order. The list must include all the details for the competition in which the pilot and his related drone participated. |
POST | Collection of pilots | Create a new pilot in the collection. |
PUT | Pilot | Update an existing pilot. |
PATCH | Pilot | Update one or more fields of an existing pilot. |
DELETE | Pilot | Delete an existing pilot. |
GET | Competition | Retrieve a single competition. The competition must include the pilot's name that made the drone reach a specific distance and the drone's name. |
GET | Collection of competitions | Retrieve all the stored competitions in the collection, sorted by distance in descending order. Each competition must include the pilot's name that made the drone reach a specific distance and the drone's name. |
POST | Collection of competitions | Create a new competition in the collection. The competition must be related to an existing pilot and an existing drone. |
PUT | Competition | Update an existing competition. |
PATCH | Competition | Update one or more fields of an existing competition. |
DELETE | Competition | Delete an existing competition. |
Scope | URI |
Collection of drone categories | /drone-categories/ |
Drone category | /drone-category/{id} |
Collection of drones | /drones/ |
Drone | /drone/{id} |
Collection of pilots | /pilots/ |
Pilot | /pilot/{id} |
Collection of competitions | /competitions/ |
Competition | /competition/{id} |
GET http://loca...