Let’s understand what an API is

Image for post
Image for post
Photo by Nina Ž. on Unsplash

What is REST?

Level 1: Correct use of URIs

{protocol}://{domain or hostname}[:port (optional)]/{resource route}?{filtering query}

URIs should not involve actions and should be unique.

URIs must be independent of format

URIs must maintain a logical hierarchy

Filtering and other operations

Level 2: HTTP

Methods

Status codes

Request
=======
PUT /invoices/123

Response
========
Status Code 200
Content:
{
success: false,
code: 734,
error: "Insufficient data"
}
Request
=======
PUT /invoices/123

Response
========
Status Code 400
Content:
{
message: "A customer id must be specified for the invoice"
}

Types and formats of content

Request
=======
GET /invoices/123
Accept: application/epub+zip, application/pdf, application/json

Response
========
Status Code 200
Content-Type: application/pdf

Level 3: Hypermedia

<order>
<id>666</id>
<status>Processed</status>
<links>
<link rel="invoice">
http://example.com/api/order/666/invoice
</link>
</links>
</order>
Request
=======
GET /order/666
Accept: application/our_api+xml, text/xml
Response
========
Status Code: 200
Content-Type: application/our_api+xml
Content:
<order>
<id>666</id>
<status>Processed</status>
<links>
<link rel="invoice">
http://example.com/api/order/666/invoice
</link>
</links>
</order>

Conclusión

Written by

Software developer @ basterrika.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store