Custom request methods in Nancy

December 2nd, 2011

Nancy is a lightweight HTTP framework for building web services and sites. The framework runs on both the .net framework and Mono.

Out of the box, Nancy supports GET, POST, PUT, PATCH, DELETE, OPTIONS and HEAD (although these are a special case of GET requests and handled differently by the framework) requests.

These are the subset of the RFC-2116 that we’ve found useful to support in Nancy. We do understand that your application might have the need to handler different kinds of requests and there are ways around this.

It’s not something we’ve specifically built Nancy to support, but because of the design we use, you can add additional handlers for other types of requests with very little effort.

In the above code I created a custom Nancy module that added a method with the name of the request verb that we want to add support for. The return type of the method is a RouteBuilder, a helper class that is used to provide the syntax Nancy uses for defining route handlers.

Once the module is created, all you have to do to start handling requests of the new method is to inherit your modules from the new base class and add your handlers.

That’s all there is to adding support for additional request methods in Nancy!

  • http://www.icu-india.com http://www.icu-india.com

    what a fantastic post and this really nice and awesome post