I don't want to explicitly write:
options { ... }
for each entry point / path in my Spray route. I'd like to write some generic code that will add OPTIONS
support for all paths. It should look at the routes and extract supported methods from them.
I can't paste any code since I don't know how to approach it in Spray.
The reason I'm doing it is I want to provide a self discoverable API that adheres to HATEOAS principles.
The below directive will be able to catch a rejected request, check if it is a option request, and return:
Try to understand the below snippet and adjust it where necessary. You should prefer to deliver as much information as possible, but if you only want to return the Allowed methods I suggest you cut out the rest :).
Use it like this:
Resource: https://github.com/giftig/mediaman/blob/22b95a807f6e7bb64d695583f4b856588c223fc1/src/main/scala/com/programmingcentre/utils/utils/CorsSupport.scala