Hands-On RESTful API Design Patterns and Best Practices
上QQ阅读APP看书,第一时间看更新

Ubiquitous web standards

As we discussed in the Goals of RESTful API design section, API designers should embrace the existing web standards and develop their API design and platforms, resulting in ubiquitous communication between the RESTful APIs and clients.

Let's ask ourselves a few questions that will help us to derive better design principles for our APIs:

  • Who will be consuming our APIs?
  • What are the business functions that the API needs to support?
  • How granular should the API be?
  • Should APIs always stick to the existing web standards and provide consistency?

The REST architecture style insists on embracing the existing web standards and so leveraging those standards should be the primary focus of any API design. The following diagram depicts a few common web methods, namely, GET, POST, PUT and DELETE , and the interactions with REST API by the clients:

After web methods, there are few essential design aspects that APIs should adhere to, and they address the questions about standardization, consumers of API, and API consistency as well:

  • Any application client should be able to use the API ideally without having to refer to much documentation
  • Use standard HTTP method call-outs, available on every language and platform, to make requests and retrieve information from APIs
  • Don't make any assumptions about the software development technologies used by consumer applications
  • Web protocol HTTP and responses such as JSON or ATOM help API clients to find a library that connects to any language or platform