# Handling the HTTP method OPTIONS

**URL:** <https://discourse.cakephp.org/t/handling-the-http-method-options/9262>\
**Category:** Need Help\
**Created:** [April 19, 2021, 9:56am UTC](https://discourse.cakephp.org/t/handling-the-http-method-options/9262 "2021-04-19T09:56:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![namatoj](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/namatoj/32/2173_2.png) [@namatoj](https://discourse.cakephp.org/u/namatoj)\
**Post date:** [April 19, 2021, 9:56am UTC](https://discourse.cakephp.org/t/handling-the-http-method-options/9262/1 "2021-04-19T09:56:47Z")

</div>

Hi!

I am implementing an API and sometimes the frontend is sending a request with the HTTP method OPTIONS ([OPTIONS - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS))

If I understand the specification correctly, you are supposed to return in the header what other methods are supported for that specific endpoint.

My question is if there is a preferred way of handling OPTIONS-requests in CakePHP? I couldn’t find anything in the documentation about that.

Right now I add OPTIONS to the `setMethods()` function for the endpoint in `routes.php` and handle the OPTIONS request in the controller action. It works, but it feels like there must be a better way of handling the OPTIONS method in CakePHP.

How do you handle OPTIONS?

Thank you!

(I’m using CakePHP 4.2)

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [April 19, 2021, 1:47pm UTC](https://discourse.cakephp.org/t/handling-the-http-method-options/9262/2 "2021-04-19T13:47:35Z")

</div>

Most of the time `OPTIONS` method is used for CORS.

Use [cakephp-cors](https://github.com/ozee31/cakephp-cors) plugin or [cors-middleware](https://github.com/tuupola/cors-middleware) for example
