OPTIONS in PHP REST API

2019-06-16 04:16发布

I'm writing a REST API in PHP and I can't find any resources explaining how to work with OPTIONS. It seems to be an important part of REST API's, that's about how much I've found.

Can anyone explain what OPTIONS should contain and how it should be formatted?

Thanks in advance.

标签: php rest
2条回答
够拽才男人
3楼-- · 2019-06-16 05:15

The HTTP OPTIONS method returns (at least) the HTTP methods that the server supports for a specific URL. Per example, if you have a resource (/user) where you can create, retrieve and retrieve headers (but not delete or update), OPTIONS should return the following response header:

Allow: GET,HEAD,POST

If you can delete the resource as well, it would be:

Allow: GET,HEAD,POST,DELETE

You get the idea.

查看更多
登录 后发表回答