Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Web Development with Sanic

You're reading from   Python Web Development with Sanic An in-depth guide for Python web developers to improve the speed and scalability of web applications

Arrow left icon
Product type Paperback
Published in Mar 2022
Publisher Packt
ISBN-13 9781801814416
Length 504 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Stephen Sadowski Stephen Sadowski
Author Profile Icon Stephen Sadowski
Stephen Sadowski
Adam Hopkins Adam Hopkins
Author Profile Icon Adam Hopkins
Adam Hopkins
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Part 1:Getting Started with Sanic
2. Chapter 1: Introduction to Sanic and Async Frameworks FREE CHAPTER 3. Chapter 2: Organizing a Project 4. Part 2:Hands-On Sanic
5. Chapter 3: Routing and Intaking HTTP Requests 6. Chapter 4: Ingesting HTTP Data 7. Chapter 5: Building Response Handlers 8. Chapter 6: Operating Outside the Response Handler 9. Chapter 7: Dealing with Security Concerns 10. Chapter 8: Running a Sanic Server 11. Part 3:Putting It All together
12. Chapter 9: Best Practices to Improve Your Web Applications 13. Chapter 10: Implementing Common Use Cases with Sanic 14. Chapter 11: A Complete Real-World Example 15. Other Books You May Enjoy

Chapter 3: Routing and Intaking HTTP Requests

Back in Chapter 1, Introduction to Sanic and Async Frameworks, we looked at a raw HTTP request to see what kind of information it includes. In this chapter, we are going to take a closer look at the first line, which contains the HTTP method and the URI path. As we learned, the most basic function of a web framework is to translate a raw HTTP request into an actionable handler. Before we see how we can implement this, it is good to keep in mind what raw requests look like:

POST /path/to/endpoint HTTP/1.1
Host: localhost:7777
User-Agent: curl/7.76.1
Accept: */*
Content-Length: 14
Content-Type: application/json
{"foo": "bar"}

Looking at the request, we see the following:

  • The first line (sometimes called the start line) contains three parts: the HTTP method, request target, and HTTP protocol.
  • The second section contains zero or more lines of HTTP headers in key: value form, with each pair separated by...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime