Using the new Service implementation, do I have to provide an Options method for all of my services?
Using the old ServiceBase approach, which all my services currently use, OPTIONS returns OK without the Access-Control-Allow-Origin header.
Here's an example:
https://github.com/JonCanning/SSCors
HelloService uses Service
GoodbyeService uses ServiceBase
Because ServiceStack's Old API enforced an interface-based API it only supported GET, POST, PUT, DELETE, PATCH requests. Handling OPTION requests we're essentially a stop-gap work-around that had a single implementation to just emit the configured headers and close the response.
With ServiceStack's New API there is no longer any limitation as you can now handle any HTTP Verb by just using its name on your IService. This now lets you handle all verbs to specific requests individually. But now it's no longer handled implicitly for you and need an implementation to handle it via a Service.
You can continue to handle all OPTIONS requests by using any of the pre-defined hooks to handle it generically before it reaches the Service.
E.g.
Plugins.Add(new CorsFeature()); //Registers global CORS Headers
this.RequestFilters.Add((httpReq, httpRes, requestDto) => {
//Handles Request and closes Responses after emitting global HTTP Headers
if (httpReq.HttpMethod == "OPTIONS")
httpRes.EndRequest();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With