Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building a RESTful Web Service with Spring

You're reading from   Building a RESTful Web Service with Spring A hands-on guide to building an enterprise-grade, scalable RESTful web service using the Spring Framework

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785285714
Length 128 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Ludovic Dewailly Ludovic Dewailly
Author Profile Icon Ludovic Dewailly
Ludovic Dewailly
Arrow right icon
View More author details
Toc

The API response format

It is up to API designers to decide which format best suits their use case. That being said, it is good practice to settle on a common response envelope format. With this approach, a RESTful web service provides a uniform interface, enabling the client developers to handle responses in a consistent manner, regardless of the operation being invoked.

The next section offers a sample envelope format.

The envelope format

The first piece of information that is relevant to any operation is whether it was successful. We can encapsulate that information with a status. Secondly, most requests will return data. Therefore, a field in our envelope could provide generic access to the response payload. The following format will form the base of any responses returned by the API:

{
  "status": "OK",
  "data": {…}
}

With this response format, we ensured that client developers will have a consistent way to check if a request was successful and access...

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
Banner background image