I found this thread Override the default Content-Type for responses in NancyFx and would've commented there, but haven't met the 50 rep reqirement yet as this is my first account after years of lurking here.
So please bear with me if this problem doesn't justify a standalone thread. I can't solve this using the search only I'm afraid. On to the topic...
--> If I have a route that returns an object or a json string there's no problem returning just that. For Example, in a NancyModule
this.Get("/patient/{id}", args => this.dataSource.GetPatientById(args.id)); // returns Patient model
returns the correctly serialized object. If I hook into the AfterRequest pipeline I can see that context.Response.StatusCode
is OK
and context.Response.ContentType
is "application/json; charset=utf-8"
as expected.
Now if I have a route that returns only a single integer, like this:
this.Get("/patient/new"), args => this.dataSource.GetNextAvailablePatientId()) // returns int Id
then Nancy apparently takes that Id as the HttpStatusCode. The AfterRequest pipeline now shows that context.Response.ContentType
is "text/html"
and context.Response.StatusCode
is the Id that I would've expected to be the actual content.
When I call the route GET /patient/new
I want it to return only i.e. 42
, not "42"
or some other notation. Is there a way to configure Nancy to return my Id this way?