Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nancyfx posting json - Nancy.DynamicDictionary is empty

Tags:

asp.net

nancy

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!

like image 723
stevef4000 Avatar asked Dec 11 '22 12:12

stevef4000


1 Answers

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 :-)

like image 60
Steven Robbins Avatar answered Dec 28 '22 05:12

Steven Robbins