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

Improving unique constraints in the models


When we created the Category model, we specified the True value for the unique argument when we created the db.Column instance named name. As a result, the migrations generated the necessary unique constraint to make sure that the name field has unique values in the category table. This way, the database won't allow us to insert duplicate values for category.name. However, the error message generated when we try to do so is not clear.

Run the following command to create a category with a duplicate name. There is already an existing category with the name equal to 'Information':

http POST :5000/api/categories/ name='Information'

The following is the equivalent curl command:

curl -iX POST -H "Content-Type: application/json" -d '{"name":"Information"}'
    :5000/api/categories/

The previous command will compose and send a POST HTTP request with the specified JSON key-value pair. The unique constraint in the category.name field won't allow the database...

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 €14.99/month. Cancel anytime}