9

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?

Sharath Zotis
  • 147
  • 1
  • 2
  • 6

3 Answers3

1

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…

Sharath Zotis
  • 147
  • 1
  • 2
  • 6
1

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.

Robert Houghton
  • 650
  • 7
  • 17
hspandher
  • 13,259
  • 1
  • 23
  • 41
  • Corrections: 1) only the URI is used to identify a resource. A resource can be anything, e.g. me, or 'happiness'. A URI plus request headers, when used over HTTP, selects a “representation of a resource” — a digital byte stream, such as a JPEG image of my likeness. 3&4) These aren't necessary for REST, other than to satisfy the common interface constraint, if using HTTP as your application protocol. Other interfaces could be chosen different from the one you describe. For example, HTML uses just GET and POST, but the interface is shared and thus satisfies REST. – Nicholas Shanks Jan 01 '17 at 15:53
  • I somewhat agree with your first proposition, that headers 'should' be used mostly for varying representations. – hspandher Jan 02 '17 at 05:48
  • I somewhat agree with your first proposition, that headers 'should' be used mostly for varying representations. But lot of times headers are used for versioning. Similarly lot of people tend to use urls for versioning. Still you can't consider these api's "unrestful". Secondly as far as correct verbs are concerned, it is recommended to use correct verbs. Besides most of the web pages using Restful urls (like Ruby on Rails does) are not actual "RESTful" since they aren't stateless (sessions). Lastly REST is only valid in the context of HTTP Protocol. You can't use REST with say SOAP. – hspandher Jan 02 '17 at 05:54
  • 1
    Regarding your final sentence, I must disagree. REST has nothing to do with HTTP, other than that it was the inspiration from which the principals of the REST *architecture style* was derived. RESTful architectures can be created for applications other than HTTP. The rest of your comment reply is talking about how REST has been misused as if that were how it should be, not, as your opening sentence of the answer says, what the "basic ideas are". Lastly, you say "to use correct verbs" but REST doesn't define what these are. As I say, HTML is restful and only uses GET and POST—those are correct. – Nicholas Shanks Jan 02 '17 at 12:28
  • Negative vote on 17 November 2017. Your 2nd point is misleading. Please delete this answer or make it community wiki – RinkyPinku Nov 17 '17 at 04:54
0

REST is a very popular architecture nowadays for development and is an approach to communications between two very different components that is often used in the development of Web Services. Besides, REST does not leverage much bandwidth which makes it a better fit for use over a network. This makes REST a better fit over SOAP because unlike SOAP you do not have to create a server and a client. In case of SOAP you have to separately create a server program to serve data and a client program that would request the data.

Detail Knowledge base can be found at http://srijan.net/blog/rest-api-and-its-utility-real-web-applications