The confluence of social networking, cloud computing, and the era of mobile applications creates a generation of emerging technologies that allow different networked devices to communicate with each other over the Internet. In the past, there were traditional and proprietary approaches for building solutions, encompassing different devices, and components communicating with each other over an unreliable network or through the Internet. Some of these approaches, such as RPC CORBA, and SOAP-based web services, which evolved as different implementations for service-oriented architecture (SOA), required a tighter coupling between components along with greater complexities in integration.
As the technology landscape evolves, today's applications are built on the notion of producing and consuming APIs instead of using web frameworks that invoke services and produce web pages. This API-based architecture enables agile development, easier adoption and prevalence, and scale and integration with applications, both within and outside the enterprise.
The widespread adoption of REST and JSON opens up the possibilities of applications incorporating and leveraging functionality from other applications as needed. Popularity of REST is mainly because it enables building lightweight, simple, and cost-effective modular interfaces, which can be consumed by a variety of clients.
The advent of mobile applications calls for a stricter delineated client-server model. Companies that build applications on iOS and Android platform can consume the REST-based API and extend and deepen their reach by combining data from multiple platforms because of the REST-based architecture that is API centric.
REST has the additional benefit of being stateless, easing scalability, visibility, and reliability as well as being platform and language agnostic. Many companies are adopting OAuth 2.0 for security and token management.
This book aims to provide avid readers with an overview of the REST architectural style, focuses on all the mentioned topics, and then dives deep into best practices and commonly used patterns for building RESTful services that are lightweight, scalable, reliable, and highly available.
Chapter 1, REST – Where It Begins, starts with the basic concepts of REST, how to design RESTful services, and best practices around designing REST resources. It covers the JAX-RS 2.0 API to build RESTful services in Java.
Chapter 2, Resource Design, discusses different request response patterns; it covers topics such as content negotiation, resource versioning, and response codes in REST.
Chapter 3, Security and Traceability, covers advanced details in security and traceability around the REST API. It includes topics such as access control, authentication using OAuth, exception handling, and auditing and validation patterns.
Chapter 4, Designing for Performance, covers the design principles needed for performance. It discusses the caching principles, asynchronous and long running jobs in REST, and how to use the partial updates using PATCH.
Chapter 5, Advanced Design Principles, covers advanced topics such as rate limiting, response pagination, and internationalization and localization principles with detailed samples. It covers extensibility, HATEOAS, and topics such as testing and documenting REST services.
Chapter 6, Emerging Standards and the Future of REST, covers real-time APIs using WebHooks, WebSockets, PuSH, and Server-sent event services, and compares and contrasts them in various areas. Additionally, this chapter covers case studies demonstrating how the emerging technologies such as WebSockets and WebHooks are being used in real-time applications. It also outlines the role of REST with micro services.
Appendix, covers different REST API from GitHub, Twitter, and Facebook, and how they tie into the principles discussed in Chapters 2, Resource Design, through Chapter 5, Advanced Design Principles.
To be able to build and run samples provided with this book, you will need the following:
Apache Maven 3.0 and higher: Maven is used to build the samples. You can download Apache Maven from http://maven.apache.org/download.cgi.
GlassFish Server Open Source Edition v4.0: This is a free community supported Application Server providing implementation for Java EE 7 specifications. You can download the GlassFish Server from http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/.
This book is a perfect reading source for application developers to get familiar with REST. It dives deep into the details, best practices, and commonly used REST patterns as well as gives insights on how Facebook, Twitter, PayPal, GitHub, Stripe, and other companies are implementing solutions with RESTful services.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "GET
and HEAD
are safe methods."
A block of code is set as follows:
@GET @Path("orders") public List<Coffee> getOrders() { return coffeeService.getOrders(); }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
@Path("v1/coffees")
public class CoffeesResource {
@GET
@Path("orders")
@Produces(MediaType.APPLICATION_JSON)
public List<Coffee> getCoffeeList( ){
//Implementation goes here
}
Any command-line input or output is written as follows:
# curl -X GET http://api.test.com/baristashop/v1.1/coffees
New terms and important words are shown in bold.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>
, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.