ebook img

Django RESTful Web Services: The easiest way to build Python RESTful APIs and web services with Django PDF

426 Pages·2018·12.208 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Django RESTful Web Services: The easiest way to build Python RESTful APIs and web services with Django

Preface Python is definitely one of the most popular programming languages. It is open source, multiplatform, and you can use it to develop any kind of application, from websites and web services to artificial intelligence and machine learning applications. You will always find a framework or a set of packages in Python to make things easier for you in any domain. It is extremely easy to work with Python and its most popular web framework, Django, in the most important and popular cloud computing providers. Hence, Python is an excellent choice for developing modern and scalable RESTful Web Services that will run on the cloud. REST (short for Representational State Transfer) is the architectural style that has been driving modern and scalable web development recently. If you want to be part of the world that builds complex web applications and mobile apps, you will need to develop and interact with RESTful Web Services. In many situations, you will have to design and develop a RESTful Web Service from scratch and maintain the API over time. A deep knowledge of RESTful Web Services is an essential skill for any software development job. This book covers everything you need to know to develop and test a RESTful Web Service from scratch with the latest version of Django, Django REST framework, and Python. You will work with real-life examples in combination with Python packages that will allow you to simplify tasks. You will learn to use a huge set of tools to test and develop a uniform, high-quality, and scalable RESTful Web Services. You will use object- oriented programming and modern Python 3.6 code to favor code reuse and simplify future maintenance. You will take advantage of automated testing to ensure that the coded RESTful Web Services run as expected. This book will allow you to create your own RESTful Web Services for any domain with Django and Django REST framework in Python 3.6 or greater. You will learn the process for the most popular Python platforms: Linux, Windows, and macOS. Who this book is for This book is for Python developers who want to develop RESTful Web Services, also known as RESTful web APIs, with Python 3.6 or greater, and want to learn how to do it with the most popular Python web framework—Django. What this book covers , Installing the Required Software and Tools, shows how to get Chapter 1 started in our journey toward creating RESTful Web Services with Python and its most popular web framework—Django. We will install and configure the environments, the software, and the tools required to create RESTful Web Services with Django and Django REST framework. We will learn the necessary steps in Linux, macOS, and Windows. We will create our first app with Django, we will take a first look at the Django folders, files, and configurations, and we will make the necessary changes to activate Django REST framework. In addition, we will introduce and install command-line and GUI tools that we will use to interact with the RESTful Web Services that we will design, code, and test in the forthcoming chapters. , Working with Models, Migrations, Serialization, and Chapter 2 Deserialization, describes how to design a RESTful Web Service to interact with a simple SQLite database and perform CRUD operations with toys. We will define the requirements for our web service, and we will understand the tasks performed by each HTTP method and the different scopes. We will create a model to represent and persist toys and execute migrations in Django to create the required tables in the database. We will analyze the tables and learn how to manage the serialization of toy instances into JSON representations with Django REST framework and the reverse process. , Creating API Views, is about executing the first version of a Chapter 3 simple Django RESTful Web Service that interacts with a SQLite database. We will write API views to process diverse HTTP requests on a collection of toys and on a specific toy. We will work with the following HTTP verbs: GET, POST, and PUT. We will configure the URL patterns list to route URLs to views. We will start the Django development server and use command-line tools (curl and HTTPie) to compose and send diverse HTTP requests to our RESTful Web Service. We will learn how HTTP requests are processed in Django and our code. In addition, we will work with Postman, a GUI tool, to compose and send other HTTP requests to our RESTful Web Service. , Using Generalized Behavior from the APIView Class, presents Chapter 4 different ways to improve our simple Django RESTful Web Service. We will take advantage of many features included in the Django REST framework to remove duplicate code and add many features for the web service. We will use model serializers, understand the different accepted and returned content types, and the importance of providing accurate responses to the HTTP OPTIONS requests. We will make the necessary changes to the existing code to enable diverse parsers and renderers. We will learn how things work under the hoods in Django REST framework. We will work with different content types and note how the RESTful Web Service improves compared to its previous versions. , Understanding and Customizing the Browsable API Feature, Chapter 5 explains how to use one of the additional features that Django REST framework adds to our RESTful Web Service—the browsable API. We will use a web browser to work with our first web service built with Django. We will learn to make HTTP GET, POST, PUT, OPTIONS, and DELETE requests with the browsable API. We will be able to easily test CRUD operations with a web browser. The browsable API will allow us to easily interact with our RESTful Web Service. , Working with Advanced Relationships and Serialization, shows Chapter 6 how to define the requirements for a complex RESTful Web Service in which we needed to work with drone categories, drones, pilots, and competitions. We will create a new app with Django and configure the new web service. We will define many-to-one relationships between the models, and we will configure Django to work with a PostgreSQL database. We will execute migrations to generate tables with relationships between them. We will also analyze the generated database and configure serialization and deserialization for the models. We will define hyperlinks and work with class-based views. Then, we will take advantage of generic classes and generic views that generalize and mix predefined behaviors. We will use routings and endpoints and prepare our RESTful Web Service to work with the browsable API. We will make many different HTTP requests to create and retrieve resources that have relationships between them. , Using Constraints, Filtering, Searching, Ordering, and Chapter 7 Pagination, describes the usage of the browsable API feature to navigate through the API with resources and relationships. We will add unique constraints to improve the consistency of the models in our RESTful Web Service. We will understand the importance of paginating results and configure and test a global limit/offset pagination scheme with Django REST framework. Then, we will create our own customized pagination class to ensure that requests won't be able to require a huge number of elements on a single page. We will configure filter backend classes and incorporate code into the models to add filtering, searching, and ordering capabilities to the class-based views. We will create a customized filter and make requests to filter, search, and order results. Finally, we will use the browsable API to test pagination, filtering, and ordering. , Securing the API with Authentication and Permissions, presents Chapter 8 the differences between authentication and permissions in Django, Django REST framework, and RESTful Web Services. We will analyze the authentication classes included in Django REST framework out of the box. We will follow the steps needed to provide security- and permissions- related data to models. We will work with object-level permissions via customized permission classes and save information about users who make requests. We will configure permission policies and compose and send authenticated requests to understand how the permission policies work. We will use command-line tools and GUI tools to compose and send authenticated requests. We will browse the secure RESTful Web Service with the browsable API feature and work with a simple token-based authentication provided by Django REST framework to understand another way of authenticating requests. , Applying Throttling Rules and Versioning Management, focuses Chapter 9 on the importance of throttling rules and how we can combine them with authentication and permissions in Django, Django REST framework, and RESTful Web Services. We will analyze the throttling classes included in Django REST framework out of the box. We will follow the necessary steps to configure many throttling policies in Django REST framework. We will work with global and scope-related settings. Then, we will use command-line tools to compose and send many requests to test how the throttling rules work. We will understand versioning classes and we will configure a URL path versioning scheme to allow us to work with two versions of our RESTful Web Service. We will use command-line tools and the Browsable API to understand the differences between the two versions. , Automating Tests, shows how to automate tests for our RESTful Chapter 10 Web Services developed with Django and Django REST framework. We will use different packages, tools, and configurations to perform tests. We will write the first round of unit tests for our RESTful Web Service, run them, and measure tests code coverage. Then, we will analyze tests code coverage reports and write new unit tests to improve the test code coverage. We will understand the new tests code coverage reports and learn the benefits of a good test code coverage. , Solutions, the right answers for the Test Your Knowledge sections Appendix of each chapter are included in the appendix. To get the most out of this book Any computer or device capable of running Python 3.6.3 or greater in Linux, macOS, or Windows. Any computer or device capable of running a modern web browser compatible with HTML 5 and CSS 3 to work with the Browsable API feature included in Django REST framework. Download the example code files You can download the example code files for this book from your account at . If you purchased this book elsewhere, you can visit www.packtpub.com www.p and register to have the files emailed directly to you. acktpub.com/support You can download the code files by following these steps: 1. Log in or register at . www.packtpub.com 2. Select the SUPPORT tab. 3. Click on Code Downloads & Errata. 4. Enter the name of the book in the Search box and follow the onscreen instructions. Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of: WinRAR/7-Zip for Windows Zipeg/iZip/UnRarX for Mac 7-Zip/PeaZip for Linux The code bundle for the book is also hosted on GitHub at https://github.com/ . We also have other code bundles PacktPublishing/Django-RESTful-Web-Services from our rich catalog of books and videos available at https://github.com/Pac . Check them out! ktPublishing/

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.