Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building RESTful Python Web Services

You're reading from  Building RESTful Python Web Services

Product type Book
Published in Oct 2016
Publisher Packt
ISBN-13 9781786462251
Pages 418 pages
Edition 1st Edition
Languages
Author (1):
Gaston C. Hillar Gaston C. Hillar
Profile icon Gaston C. Hillar

Table of Contents (18) Chapters

Building RESTful Python Web Services
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
1. Developing RESTful APIs with Django 2. Working with Class-Based Views and Hyperlinked APIs in Django 3. Improving and Adding Authentication to an API With Django 4. Throttling, Filtering, Testing, and Deploying an API with Django 5. Developing RESTful APIs with Flask 6. Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask 7. Improving and Adding Authentication to an API with Flask 8. Testing and Deploying an API with Flask 9. Developing RESTful APIs with Tornado 10. Working with Asynchronous Code, Testing, and Deploying an API with Tornado 11. Exercise Answers

Composing requests with the necessary authentication


Now, we will compose and send an HTTP request to retrieve the first page of the messages without authentication credentials:

http POST ':5000/api/messages/?page=1'

The following is the equivalent curl command:

curl -iX GET ':5000/api/messages/?page=1'

We will receive a 401 Unauthorized status code in the response header. The following lines show a sample response:

HTTP/1.0 401 UNAUTHORIZED
Content-Length: 19
Content-Type: text/html; charset=utf-8
Date: Mon, 15 Aug 2016 01:16:36 GMT
Server: Werkzeug/0.11.10 Python/3.5.1
WWW-Authenticate: Basic realm="Authentication Required"

If we want to retrieve messages, that is, to make a GET request to /api/messages/, we need to provide authentication credentials using HTTP authentication. However, before we can do this, it is necessary to create a new user. We will use the new user to test our new resource classes related to users and our changes in the permissions policies.

http POST :5000/api/users...
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 $15.99/month. Cancel anytime}