Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Gaston C. Hillar

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, project-driven guide for Python developers who want to build production-ready RESTful APIs with Django and Django REST framework, covering everything from the first model to testing and versioning. 【Book Arc】 - **Opening (~0%–10%)**: Sets up the development environment (virtual environments, Django installation) and introduces the core tools (curl, HTTPie, Postman) used throughout the book to compose and send HTTP requests. - **Early (~10%–23%)**: Builds the first RESTful web service around a "toys" model — creating models, running migrations, writing serializers, and understanding the two-phase serialization/deserialization process in Django REST framework. - **Early (~23%–32%)**: Implements function-based views with the `@api_view` decorator, moves from a JSON-only parser to the generic `Response` class, and configures URL routing for GET, POST, PUT, and DELETE operations. - **Middle (~32%–48%)**: Transitions to a more complex "drones" project with PostgreSQL, introduces class-based views, and covers the browsable API — a web interface for interacting with the service — plus routing for related resources (drones, pilots, competitions) and PATCH/OPTIONS methods. - **Late (~48%–end)**: Covers advanced topics: throttling rules combined with authentication and permissions, URL path versioning for maintaining multiple API versions, and automated testing with unit tests and code coverage measurement. 【Key Takeaways】 - **Environment isolation matters** (Early): Using virtual environments ensures package installations don't affect your main Python setup; the book walks through activation scripts for different shells (bash, zsh, csh) on Linux, macOS, and Windows. - **Serializers are the heart of Django REST framework** (Early): They act as mediators between model instances and Python primitives, using a two-phase process for serialization; understanding this is critical for all subsequent API development. - **The `@api_view` decorator simplifies API views** (Early): Replacing custom `JSONResponse` classes with the generic `Response` class and removing hardcoded JSON parsers makes views flexible enough to support multiple content types with minimal code. - **The browsable API is a powerful debugging tool** (Middle): Opening `http://localhost:8000/toys/` in a browser renders an interactive HTML page that can compose and send GET, POST, and DELETE requests, showing status codes like 201 Created and 204 No Content. - **PUT vs. PATCH semantics matter** (Middle): PUT replaces an entire resource, while PATCH applies a delta (updates one or more fields); supporting both, plus OPTIONS, makes the web service consistent and complete. - **PostgreSQL integration is straightforward** (Middle): Swapping SQLite for PostgreSQL only requires changing the `DATABASES` dictionary in settings — the ORM and migrations handle table creation and foreign keys automatically. - **Throttling and versioning are essential for production APIs** (Late): Combining throttling rules with authentication and permissions protects resources, while URL path versioning lets you maintain multiple API versions simultaneously. - **Automated tests with coverage reports improve code quality** (Late): Writing unit tests, running them, and analyzing coverage reports helps identify untested code paths and leads to more robust web services. 【Reading Tips】 - **Skim the environment setup** (Opening–Early) if you're already comfortable with virtual environments and pip; the key takeaway is the tool list (curl, HTTPie, Postman) used throughout. - **Deep-read the serialization chapter** (Early ~13%–19%) — it's foundational for everything else; understanding the two-phase process and the `JSONParser` class will save you hours later. - **Follow along with the code** — the book provides complete file paths and code snippets; type them out or download the samples to see how each piece fits together. - **Use the browsable API as a learning aid** (Middle) — it's not just a tool; it demonstrates how the web service behaves under the hood, making it easier to debug your own code. - **Pay attention to the transition from function-based to class-based views** (Middle) — this is where the book shifts from simple examples to more scalable patterns that you'll use in real projects. 【Coverage Limits】 The excerpts cover roughly the first half of the book in detail (environment, first service, serializers, views, browsable API, PostgreSQL setup). Advanced topics like throttling, versioning, and testing are mentioned in the table of contents but not detailed in the sample chunks.
Page 15
our authors can see your feedback on their book. Thank you! For more information about Packt, please visit : packtpub.com. Activating the virtual environment...
View in text
Excerpt 2
mediators between the model instances and Python primitives. Parser and renderers handle as mediators between Python primitives and HTTP requests and respons...
View in text
Excerpt 3
ge amount of code to do so. Thus, we will take advantage of additional features included in the Django REST framework that will make it easy for us to suppor...
View in text
Excerpt 4
ources. This way, we will provide a consistent web service. We will use the ORM (short for Object-Relational Mapping) included in Django. In addition, we wil...
View in text
Excerpt 5
"name": "Penelope Pitstop", "races_count": 0, "url": "http://localhost:8000/pilots/1" } The PilotSerializer class defined the competitions attribute as a Com...
View in text
Excerpt 6
'name', 'manufacturing_date', ) In the DroneList class, we specified many field names in the filter_fields attribute. We included 'drone_category' in the str...
View in text
Excerpt 7
of the drone, and therefore, the request shouldn't succeed. Replace user01 and user01password in the next command with the name and password you configured f...
View in text
Excerpt 8
/drones/views.py file and add the following lines after the last line that declares the imports, before the declaration of the DroneCategoryList class: from...
View in text
Tags
AI categories
PythonBackendProgramming Language
ISBN: 1788833929
Publisher: Packt Publishing
Publish Year: 2018
Language: English
File Format: PDF
File Size: 12.2 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…