Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a Rest API [duplicate]

Tags:

rest

api

What is Rest API, why is it used, and how can I go about creating one and learning more about it? All functions should be of either GET/POST/DELETE/PUT form?

like image 766
Sharath Zotis Avatar asked Dec 29 '16 09:12

Sharath Zotis


2 Answers

Simply, a REST API defines a set of functions which developers can perform requests and receive responses via HTTP protocol such as GET and POST. The REST API should specify what it can provide and how to use it, details such as query parameters, response format, request limitations, public use/API keys, method (GET/POST/PUT/DELETE), language support, callback usage, HTTPS support and resource representations should be self-descriptive…

like image 177
Sharath Zotis Avatar answered Oct 21 '22 19:10

Sharath Zotis


REST is a highly scalable and cachable architecture that is ideal for designing APIs. Basic ideas behind REST -

  1. URL and headers should uniquely identify the resource, such that it can be cached.

  2. REST APIs should be stateless i.e. result of an API call shouldn't vary depending on the API calls preceding it. Keeping state across APIs restricts caching and is thus not considered RESTful.

  3. Use appropriate HTTP verbs i.e. GET for read and idempotent requests, POST for write requests, PUT for write and idempotent requests, DELETE for deletion of resources.

  4. Return appropriate status codes that are compliant with REST standards for the ease of use and universal cachability over different proxy layers.

  5. HATEOAS i.e. Hypermedia as the engine of application state which states that most of the URLS shouldn't be hardcoded, instead server-side should guide the client by providing the URLs in its response. The idea is quite akin to how we use websites on our browsers.

like image 38
hspandher Avatar answered Oct 21 '22 19:10

hspandher