Design OPTIONS to Inform Clients About Supported Operations

Understand the OPTIONS method and design the products API to inform clients about supported operations.

Inform clients about supported operations

A client should be able to query a service for the list of supported operations. In the world of REST APIs, that is achieved by issuing an OPTIONS request to the service. Conversely, a REST service uses the OPTIONS method to inform clients about the supported operations.

According to the specificationsPackage org.jboss.netty.handler.codec.http, “The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI.”

According to the above specification, the OPTIONS method has the following features:

  • It’s idempotent. That means multiple OPTIONS requests to the same URI with the same parameters will result in the same effect on the server as a single OPTIONS request.
  • The response should provide all the operations supported by the service as a part of the response header.
  • Body is optional for both the request and the response.
  • A 200 OK response will include any optional features implemented by the service.
  • Responses are not cacheable.

Similar to GET or DELETE, OPTIONS request has an optional body, and similar to POST, it doesn’t specify a specific resource ID.

Get hands-on with 1200+ tech skills courses.