Response Building

The response is represented as the IHttpResponse interface which defines HTTP status code, HTTP headers and HTTP body content. The basic implementation of the HttpResponse provides universal constructors to build any type of response. Also there are a few implementations to increase usability.

Besides several prepared responses were added which are used very often:

Result Converters

The response can be any model and the final result will be determined by the ResultConverter which defines conversion rules from the source model to the IHttpResponse instance. If a module does not set the ResultConverter then the default conversion rules are used. They are represented in the DefaultHttpResultConverter class:

Next converter wraps a result to the JSON object with a single property Result.

 builder.ResultConverter = result =>
 {
     return (result is IHttpResponse)
         ? (IHttpResponse)result
         : new JsonHttpResponse(new { Result = result });
 };

 builder.Get["/some"] = request =>
 {
     return Task.FromResult<object>(123); // {"Result":123 }
 };