What is a Rest API for front and backend communication?

Asked

Viewed 2,168 times

0

I couldn’t understand what a Rest API is for front and backend communication

1 answer

1


The Representational State Transfer (REST), in Portuguese Representational State Transfer, is an abstraction of the architecture of the World Wide Web, more precisely, is an architectural style consisting of a coordinated set of architectural constraints applied to components, connectors and data elements within a distributed hypermedia system.

REST ignores the details of component implementation and protocol syntax in order to focus on component roles, constraints on their interaction with other components, and their interpretation of significant data elements.

It was officially defined by W3C.

It is often applied to web services providing Apis for access to any service on the web. It fully uses HTTP messages to communicate through what is already defined in the protocol without having to "invent" new protocols specific to that application.

You essentially work with components, connectors and data.

It uses the HTTP protocol (verbs, Accept headers, HTTP state codes, Content-Type) explicitly and representatively to communicate. Uris are used to expose the structure of the service. It uses a common notation for data transfer such as XML or JSON. There is no state between these communications, that is, each communication is independent and uniform (standardized) needing to pass all necessary information. It should facilitate client content caching. It must have a clear definition of what is part of the client and the server. The client does not need to know how the server stores data, for example. So each implementation does not depend on the other and becomes more scalable. Allows use in layers also facilitating scalability, reliability and security. It is often created with some form of extensibility.

Example:

http://example.com/apagar/produto/1234 means you are asking to erase the product from ID 1234.

Some say this is wrong and since the emphasis is on resources and not on operations. You should use it like this:

http://example.com/produto/1234 (using the verb DELETE) Let’s face it, this can be used for CRUD, but there are so many variations of what needs to be done that it is not possible to represent everything with just the HTTP verbs. Okay, it’s possible to make everything look CRUD, but it may require additional information in the name of formalism.

All of this is designed to provide better performance, scalability, simplicity, flexibility, visibility, portability and reliability.

Each defines how you want your API, unlike SOAP where everything is set officially.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.