REST
According to Wikipedia:
It is thought of how an image of the application design will behave.
That is, it would be something like, depending on how you consume the same feature - a feature that can be visually identified inclusive - your behavior will change.
Let's illustrate to facilitate:
About HTTP Requests
Every time we access something via browser, multiple requests are triggered. When you access any page, a request for the content of that page is created. When this content returns, the browser mounts (renders)the page, but this page requires other features such as images, fonts, stylesheets (css). For each feature, the browser will make a new request.
These requests are composed mainly of three information:
- URL: Address that will receive the request;
- Verb/Method: Command that is desired to be made;
- Body: Information we send, such as data from a form, for example.
As many as the Verbs, there are 4 that are the most used:
- GET: Used to bring information
- POST: To create/add information
- PUT: To tulize information
- DELETE: To delete information ## RESTful Service
They are services that have REST behavior. That is, using the same design, your behavior will change according to the way it is consumed
For example, we have the URL(endpoint)below:
http://www.contoso.com/students
If we want to bring the list of students, just make a request: GET
Request:
[GET] http://www.contoso.com/students
Body: empty
The answer will be something like:
Response:
HTTP Code 200 OK
[
{ id: 1, nome: "Thiago Lunardi" },
{ id: 2, nome: "Joe Satriani"}
]
But if I want to add a new student, I use the same design, but consuming otherwise, with a request: POST
Request:
[POST] http://www.contoso.com/students
Body: { "nome: "Slash" }
HTTP Code 201 Created
{ id: 3, nome: "Slash" }
Continuing, to learn more about a student:
Request:
[GET] http://www.contoso.com/students/1
Body: empty
Response:
HTTP Code 200 OK
{
id: 1,
nome: "Thiago Lunardi",
github: "https://github.com/ThiagoLunardi",
website: "http://thiagolunardi.net",
blog: "https://medium.com/@thiagolunardi",
}
To update one-year information, in the same way, we use the same design, and we just change the way we consume the resource, and it will behave differently:
Request:
[PUT] http://www.contoso.com/alunos/1
Body: { "twitter": "@thiagolunardi13" }
Response:
HTTP Code 200 OK
{
id: 1,
nome: "Thiago Lunardi",
github: "https://github.com/ThiagoLunardi",
website: "http://thiagolunardi.net",
blog: "https://medium.com/@thiagolunardi",
twitter: "@thiagolunardi13"
}
To delete:
Request:
[DELETE] http://www.contoso.com/alunos/1
Body: empty
Response:
HTTP Code 204 No Content
PS: Translated from StackOverflow.