I'm just starting to play with NancyFx to compare it with the .net MVC WebAPI stuff and I've hit an issue straight away. As I understand it Nancy should handle serialization straight out of the box. But I can't seem to get it working.
I have a Nancy Module that looks like this:
public class HelloWorld : NancyModule
{
public HelloWorld()
{
Post["/"] = parameters =>
{
var myFieldValue = parameters.myField;
return HttpStatusCode.OK;
};
}
}
And I post to it using Fiddler like this:
Headers:
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:3141
Content-Length: 24
Request-Body:
{"myField" : "profit"}
However when the parameters object is empty (and so, therefore is the myFieldValue object). I'm sure I've missed something really obvious, but I don't know what!
Parameters are for captures in the url (e.g. /foo/{bar} would capture a bar variable in parameters. If you are posting JSON you should use the model binder (var foo =this.Bind();
I would recommend taking a look at the docs too.. All of this is covered there :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With