Representational state transfer or REST API is a way of providing interoperability between computer systems and applications on the Internet. It was developed to show how a well-designed app should behave. It can be described as a huge network of resources where a user selects links and operations such as GET or POST to move through the application and proceed to the next resource that represents the next state of the app.
RESTful application allows systems to access textual representations of web resources using a certain set of predefined operations. GET, POST, PUT, DELETE are the most common kinds of operations or verbs available if using HTTP. In a REST web service, made requests will receive a response that may be in XML, HTML, JSON or some other defined format. The response may confirm that certain alterations have been made to the resource or it may provide a hypertext link to other common resources available.
REST systems are mostly valued for fast performance, reliability and effective scalability. As it is well-known the REST architectural style takes into account six constraints that are applied to the architecture, were originally communicated by Roy Fielding in his doctoral dissertation. They define the basis of RESTful-style.
The Six Constraints Are as Follows
Code on Demand (optional)
Let’s take a look at them in more detail:
The first constraint is focused on separating the user interface concerns from the data storage concerns. This improves the portability of the user interface across different platforms and improves scalability; it also allows the components to evolve independently.
Stateless means without state. All the data are directly sent to the client and no client context is stored on the server.
This approach has lots of advantages:
There is no need for a storage on the server side.
The data will expire automatically if an application forgets about its access token.
Systems can be entirely decoupled as there is a shared token storage.
This means that clients can cache responses if they define themselves as cacheable. The major benefit of caching is that it partially or completely eliminates some client–server interactions and improves scalability and performance.
A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary server. Intermediary servers usually improve scalability as they enable load balancing, provide shared caches, enforcing security policies.
Code on demand (optional)
A fundamental constraint for any REST service is the uniform interface.
The four constraints for the uniform interface are as follows:
Identification of resources (individual resources are identified in requests).
Manipulation of resources through representations (when a client holds a representation of a resource, it has enough information to modify or delete the resource).
Self-descriptive messages (each message includes enough information to describe how to process the message).
Hypermedia as the engine of application state (REST client should be able to use server-provided links dynamically to discover all the available actions and resources it needs).
If an app violates any of the required constraints, it cannot be considered RESTful.
One of the most popular tools to represent your RESTful API is Swagger. It is already used by hundred thousands of developers worldwide supporting almost every programming language and deployment environment. When choosing Swagger-enabled APIs you have the benefit of working with client SDK generation, interactive documentation and discoverability.
Swagger is widely used by such companies as: Apigee, LivingSocial, Getty Images, Intuit, McKesson, Microsoft, Morningstar, and PayPal. A great news is that starting November 2016 Swagger 2.0 is 100% open source software.
Let’s Take a Look at the Most Popular Swagger Tools and Resources:
Swagger Editor can be used to design Swagger specifications with a simple YAML structure.
Swagger SDK Generators make it possible to turn an API specification into client SDKs or server-side code using Swagger Codegen.
Server Integrations provide dozens of integration options for putting Swagger in your API. You just need to pick your language and framework.
Services include API management services and Platform as a Service solutions.
In a nutshell, it is quite obvious that Swagger is one of the world’s most popular frameworks for APIs. If you haven’t used it before, just give it a try and see if it works for you.
To sum it all up, REST APIs are very useful for building huge scalable systems where caching is acceptable. A good REST app will use a small number of verbs, sophisticated representations (XML or JSON), caching, scalability, reduced server load and statelessness on the server.