Django RESTful Web Services

Design, build and test RESTful web services with the Django framework and Python
Preview in Mapt

Django RESTful Web Services

Gastón C. Hillar

Design, build and test RESTful web services with the Django framework and Python

Quick links: > What will you learn?> Table of content

Mapt Subscription
FREE
$29.99/m after trial
eBook
$22.40
RRP $31.99
Save 29%
Print + eBook
$39.99
RRP $39.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
$22.40
$39.99
$29.99 p/m after trial
RRP $31.99
RRP $39.99
Subscription
eBook
Print + eBook
Start 14 Day Trial

Frequently bought together


Django RESTful Web Services Book Cover
Django RESTful Web Services
$ 31.99
$ 22.40
Building RESTful Web Services with Spring 5 - Second Edition Book Cover
Building RESTful Web Services with Spring 5 - Second Edition
$ 35.99
$ 25.20
Buy 2 for $35.00
Save $32.98
Add to Cart

Book Details

ISBN 139781788833929
Paperback326 pages

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.

Table of Contents

Chapter 1: Installing the Required Software and Tools
Creating a virtual environment with Python 3.x and PEP 405
Installing Django and Django REST frameworks in an isolated environment
Creating an app with Django
Installing tools
Test your knowledge
Summary
Chapter 2: Working with Models, Migrations, Serialization, and Deserialization
Defining the requirements for our first RESTful Web Service
Creating our first model
Running our initial migration
Analyzing the database
Controlling, serialization, and deserialization
Working with the Django shell and diving deeply into serialization and deserialization
Test your knowledge
Summary
Chapter 3: Creating API Views
Creating Django views combined with serializer classes
Understanding CRUD operations with Django views and the request methods
Routing URLs to Django views and functions
Launching Django's development server
Making HTTP POST requests with Postman
Test your knowledge
Summary
Chapter 4: Using Generalized Behavior from the APIView Class
Taking advantage of model serializers
Understanding accepted and returned content types
Making unsupported HTTP OPTIONS requests with command-line tools
Understanding decorators that work as wrappers
Using decorators to enable different parsers and renderers
Taking advantage of content negotiation classes
Making supported HTTP OPTIONS requests with command-line tools
Working with different content types
Sending HTTP requests with unsupported HTTP verbs
Test your knowledge
Summary
Chapter 5: Understanding and Customizing the Browsable API Feature
Understanding the possibility of rendering text/HTML content
Using a web browser to work with our web service
Making HTTP GET requests with the browsable API
Making HTTP POST requests with the browsable API
Making HTTP PUT requests with the browsable API
Making HTTP OPTIONS requests with the browsable API
Making HTTP DELETE requests with the browsable API
Test your knowledge
Summary
Chapter 6: 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 viewsets
Generalizing and mixing behavior
Working with routing and endpoints
Making requests that interact with resources that have relationships
Test your knowledge
Summary
Chapter 7: Using Constraints, Filtering, Searching, Ordering, and Pagination
Browsing the API with resources and relationships
Defining unique constraints
Working with unique constraints
Understanding pagination
Configuring pagination classes
Making requests that paginate results
Working with customized pagination classes
Making requests that use customized paginated results
Configuring filter backend classes
Adding filtering, searching, and ordering
Working with different types of Django filters
Making requests that filter results
Composing requests that filter and order results
Making requests that perform starts with searches
Using the browsable API to test pagination, filtering, searching, and ordering
Test your knowledge
Summary
Chapter 8: Securing the API with Authentication and Permissions
Understanding authentication and permissions in Django, the Django REST framework, and RESTful Web Services
Learning about the authentication classes
Including security and permissions-related data to models
Working with object-level permissions via customized permission classes
Saving information about users that make requests
Setting permission policies
Creating the superuser for Django
Creating a user for Django
Making authenticated requests
Making authenticated HTTP PATCH requests with Postman
Browsing the secured API with the required authentication
Working with token-based authentication
Generating and using tokens
Test your knowledge
Summary
Chapter 9: Applying Throttling Rules and Versioning Management
Understanding the importance of throttling rules
Learning the purpose of the different throttling classes in the Django REST framework
Configuring throttling policies in the Django REST framework
Running tests to check that throttling policies work as expected
Understanding versioning classes
Configuring a versioning scheme
Running tests to check that versioning works as expected
Test your knowledge
Summary
Chapter 10: Automating Tests
Getting ready for unit testing with pytest
Writing unit tests for a RESTful Web Service
Discovering and running unit tests with pytest
Writing new unit tests to improve the tests' code coverage
Running unit tests again with pytest
Test your knowledge
Summary
Chapter 11: Solutions
Chapter 1: Installing the Required Software and Tools
Chapter 2: Working with Models, Migrations, Serialization, and Deserialization
Chapter 3: Creating API Views
Chapter 4: Using Generalized Behavior from the APIView Class
Chapter 5: Understanding and Customizing the Browsable API Feature
Chapter 6: Working with Advanced Relationships and Serialization
Chapter 7: Using Constraints, Filtering, Searching, Ordering, and Pagination
Chapter 8: Securing the API with Authentication and Permissions
Chapter 9: Applying Throttling Rules and Versioning Management
Chapter 10: Automating Tests

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

Authors

Table of Contents

Chapter 1: Installing the Required Software and Tools
Creating a virtual environment with Python 3.x and PEP 405
Installing Django and Django REST frameworks in an isolated environment
Creating an app with Django
Installing tools
Test your knowledge
Summary
Chapter 2: Working with Models, Migrations, Serialization, and Deserialization
Defining the requirements for our first RESTful Web Service
Creating our first model
Running our initial migration
Analyzing the database
Controlling, serialization, and deserialization
Working with the Django shell and diving deeply into serialization and deserialization
Test your knowledge
Summary
Chapter 3: Creating API Views
Creating Django views combined with serializer classes
Understanding CRUD operations with Django views and the request methods
Routing URLs to Django views and functions
Launching Django's development server
Making HTTP POST requests with Postman
Test your knowledge
Summary
Chapter 4: Using Generalized Behavior from the APIView Class
Taking advantage of model serializers
Understanding accepted and returned content types
Making unsupported HTTP OPTIONS requests with command-line tools
Understanding decorators that work as wrappers
Using decorators to enable different parsers and renderers
Taking advantage of content negotiation classes
Making supported HTTP OPTIONS requests with command-line tools
Working with different content types
Sending HTTP requests with unsupported HTTP verbs
Test your knowledge
Summary
Chapter 5: Understanding and Customizing the Browsable API Feature
Understanding the possibility of rendering text/HTML content
Using a web browser to work with our web service
Making HTTP GET requests with the browsable API
Making HTTP POST requests with the browsable API
Making HTTP PUT requests with the browsable API
Making HTTP OPTIONS requests with the browsable API
Making HTTP DELETE requests with the browsable API
Test your knowledge
Summary
Chapter 6: 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 viewsets
Generalizing and mixing behavior
Working with routing and endpoints
Making requests that interact with resources that have relationships
Test your knowledge
Summary
Chapter 7: Using Constraints, Filtering, Searching, Ordering, and Pagination
Browsing the API with resources and relationships
Defining unique constraints
Working with unique constraints
Understanding pagination
Configuring pagination classes
Making requests that paginate results
Working with customized pagination classes
Making requests that use customized paginated results
Configuring filter backend classes
Adding filtering, searching, and ordering
Working with different types of Django filters
Making requests that filter results
Composing requests that filter and order results
Making requests that perform starts with searches
Using the browsable API to test pagination, filtering, searching, and ordering
Test your knowledge
Summary
Chapter 8: Securing the API with Authentication and Permissions
Understanding authentication and permissions in Django, the Django REST framework, and RESTful Web Services
Learning about the authentication classes
Including security and permissions-related data to models
Working with object-level permissions via customized permission classes
Saving information about users that make requests
Setting permission policies
Creating the superuser for Django
Creating a user for Django
Making authenticated requests
Making authenticated HTTP PATCH requests with Postman
Browsing the secured API with the required authentication
Working with token-based authentication
Generating and using tokens
Test your knowledge
Summary
Chapter 9: Applying Throttling Rules and Versioning Management
Understanding the importance of throttling rules
Learning the purpose of the different throttling classes in the Django REST framework
Configuring throttling policies in the Django REST framework
Running tests to check that throttling policies work as expected
Understanding versioning classes
Configuring a versioning scheme
Running tests to check that versioning works as expected
Test your knowledge
Summary
Chapter 10: Automating Tests
Getting ready for unit testing with pytest
Writing unit tests for a RESTful Web Service
Discovering and running unit tests with pytest
Writing new unit tests to improve the tests' code coverage
Running unit tests again with pytest
Test your knowledge
Summary
Chapter 11: Solutions
Chapter 1: Installing the Required Software and Tools
Chapter 2: Working with Models, Migrations, Serialization, and Deserialization
Chapter 3: Creating API Views
Chapter 4: Using Generalized Behavior from the APIView Class
Chapter 5: Understanding and Customizing the Browsable API Feature
Chapter 6: Working with Advanced Relationships and Serialization
Chapter 7: Using Constraints, Filtering, Searching, Ordering, and Pagination
Chapter 8: Securing the API with Authentication and Permissions
Chapter 9: Applying Throttling Rules and Versioning Management
Chapter 10: Automating Tests

Book Details

ISBN 139781788833929
Paperback326 pages
Read More

Read More Reviews

Recommended for You

Building RESTful Web Services with Spring 5 - Second Edition Book Cover
Building RESTful Web Services with Spring 5 - Second Edition
$ 35.99
$ 25.20
Building PHP RESTful Web Services [Video] Book Cover
Building PHP RESTful Web Services [Video]
$ 124.99
$ 106.25
Building RESTful Python Web Services with Django [Video] Book Cover
Building RESTful Python Web Services with Django [Video]
$ 124.99
$ 106.25
Building RESTful Web services with Go Book Cover
Building RESTful Web services with Go
$ 35.99
$ 25.20
Scalable Java 9 for the Connected Web [Video] Book Cover
Scalable Java 9 for the Connected Web [Video]
$ 124.99
$ 106.25
Test Driven Web Application Development with Ember [Video] Book Cover
Test Driven Web Application Development with Ember [Video]
$ 124.99
$ 106.25