When using ServiceStack to create a REST service, how do you handle arbitrary HTTP verbs?
The most common verbs have very simple methods. For example, to handle a GET request I would do the following:
public class MyService : RestServiceBase<MyRequest>
{
public override object OnGet(MyRequest request){
//do stuff and return HttpResult or object for serialization
}
}
Similar overrides exist for PUT, POST, DELETE, and PATCH.
What do I do if I want to use HEAD or some other verb?
(I’ve looked through the documentation and examples and other ServiceStack questions but haven’t found anything that indicates the correct way to do this.)
ServiceStack’s RestServiceBase class already has built-in support for GET, POST, PUSH, DELETE and PATCH. so you just override it as you would your
OnGet()method, e.g. you can handle DELETE requests with:For HEAD requests you currently can’t handle this in a ServiceStack service so you will need to handle it in either a RequestFilter or RequestFitler Attribute (make sure you close the httpRes to terminate the request).
You also have the opportunity to by-pass the ServiceStack pipeline completely by registering your own Custom IHttpHandler in the EndpointHostConfig.RawHttpHandlers config in your AppHost.