Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restful web services

Tags:

rest

What do you need to avoid in setting up a Restful interface to make sure you have not turned it into an RPC?

like image 664
Jeff Waltzer Avatar asked Jul 29 '09 20:07

Jeff Waltzer


People also ask

What are the RESTful web services?

Restful Web Services is a stateless client-server architecture where web services are resources and can be identified by their URIs. REST Client applications can use HTTP GET/POST methods to invoke Restful web services.

What is REST API and RESTful web services?

REST stands for representational state transfer. It is a set of constraints that set out how an API (application programming interface) should work. If an API is RESTful, that simply means that the API adheres to the REST architecture.

Why RESTful web services are used?

Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery.

What is RESTful API example?

An application implementing a RESTful API will define one or more URL endpoints with a domain, port, path, and/or query string — for example, https://mydomain/user/123?format=json . The HTTP method.


2 Answers

Do:

  • Design your application to be hypertext-driven (Hypermedia as the Engine of Application State - HATEOAS).
  • Spend most of your time and effort identifying resources and crafting media types to represent them.
  • Think of the entire URI as your resource identifier, and assume it will change in the future.
  • Provide all options for continuing further through your application as links in your representation.
  • Think of your application as website that will be 'crawled' or 'browsed' by clients.
  • Try writing a client for your API and look for where the coupling occurs.

Don't:

  • Publish URI templates in API documentation. If you must have templates for query parameters for example, make sure they're part of your media type definition.
  • Think of your application as a collection of URIs being acted on by four verbs.
  • Serve mime types such as "application/xml" or "application/json" to clients.

To use an analogy, your API should work more like a GPS for your clients and less like a map. You'll only provide clients with the name of a nearby street. But from then on, they can only do what your application says they can do at any given point.

The purpose of this style is to minimize coupling between your application and its clients. All of the coupling should occur in your media type definition. This simplifies the evolution of the API, and provides a nice mechanism for versioning. It also makes questions about issues such as pagination disappear.

Most "RESTful" APIs don't follow this pattern. For one that does, see the Sun Cloud API and its backstory.

like image 86
Rich Apodaca Avatar answered Sep 28 '22 01:09

Rich Apodaca


Take advantage of the underlying protocol where possible. Instead of having verbs in your payload try to use (for example) the HTTP GET, POST, PUT, DELETE methods. Your URI should describe a resource but not what to do with it.

like image 35
Bob Gettys Avatar answered Sep 28 '22 01:09

Bob Gettys