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
RESTful Web API Design with Node.js 10, Third Edition

You're reading from   RESTful Web API Design with Node.js 10, Third Edition Learn to create robust RESTful web services with Node.js, MongoDB, and Express.js

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher Packt
ISBN-13 9781788623322
Length 178 pages
Edition 3rd Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Valentin Bojinov Valentin Bojinov
Author Profile Icon Valentin Bojinov
Valentin Bojinov
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. REST – What You Did Not Know FREE CHAPTER 2. Getting Started with Node.js 3. Building a Typical Web API 4. Using NoSQL Databases 5. Restful API Design Guidelines 6. Implementing a Full Fledged RESTful Service 7. Preparing a RESTful API for Production 8. Consuming a RESTful API 9. Securing the Application 10. Other Books You May Enjoy

Handling HTTP status codes on the client side


We spent quite some time addressing how RESTful services should represent each state, including erroneous ones, gracefully. A well-defined API should demand from its consumers to handle all its errors gracefully and to provide as much information per state as required, rather than just stating "An error has occurred". That is why it should look up the returned status code and clearly distinguish between client requests such as 400 Bad Request or 415 Unsupported media types caused by faulty payload, caused by wrong media types, or authentication-related errors, such as 401 Unauthorized.

The status code of an erroneous response is available in the error callback of the jQuery callback function and should be used to provide detailed information back to the request:

 $.ajax({
        url: "http://localhost:3000/catalog/v2/",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(newItem),
        success: function (item, status...
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 $19.99/month. Cancel anytime