Implementing OPTIONS to Inform Clients About Supported Operation

Learn how to implement our API using Flask to inform clients about supported operations.

In REST, when a client needs to query a service about the operations it supports, the client issues an OPTIONS request. The OPTIONS request is always issued against the root of the service. Hence, from a URI perspective, OPTIONS and POST use the same template. We’ll see how to implement the OPTIONS endpoint to inform the clients about the operations that the products API supports.

In Flask, to provide a custom OPTIONS response, we need to return the response from a method decorated with the @after_request decorator. Let’s see how to use @after_request to provide our own response to an OPTIONS request.

Get hands-on with 1200+ tech skills courses.