0

After navigate to http://localhost:57645 code below returns 200 (OK) for DHC by Restlet and 500 (InternalServerError) for "Chrome Browser".

public class SampleModule : Nancy.NancyModule
{
    public SampleModule()
    {
        Get["/"] = _ =>
        {
            return Negotiate
                .WithStatusCode(HttpStatusCode.OK)
                .WithModel(10);
        };
}

How is this possible?

Filip
  • 3,002
  • 1
  • 26
  • 37
user2217261
  • 455
  • 7
  • 18

2 Answers2

2

The behavior you're experiencing in the first example is expected. The browser is requesting text/html

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Nancy is attempting to locate a view based on the type 10, since 10 is a type of Int32, Nancy is trying to find a view called Int32 since its trying to response with a View, since that's what the browser asked for.

The Dev Client you're using in Chrome is most likely sending a request for JSON by default which is why it appears to be working.

You can read more about this here:

http://www.philliphaydon.com/2013/04/nancyfx-revisiting-content-negotiation-and-apis-part-1/

Phill
  • 18,398
  • 7
  • 62
  • 102
0

Found it! In my case best to use

return Response.AsJson(10);
user2217261
  • 455
  • 7
  • 18