JulianP
JulianP

Reputation: 97

How do I get data from a POST request on Nancy 2.0?

I need to implement a POST request handler using NancyFX 2.0. As opposed to a GET request, I don't understand how to handle the POST on Nancy 2.0, as there isn't any data on the url nor in the parameters variable.

My code is currently as follows:

My NancyModule Post method:

Post("/add/{firstname:string}", parameters => AddAction(parameters));

AddAction Method:

dynamic AddAction(dynamic parameters)
   {
    //I would need to print the JSON or bind it into a Client object here
   }

And this is my Client class:

public Client(int id, string firstName, string lastName, string address)
   {
       ID = id; 
       FirstName = firstName;
       LastName = lastName;
       Address = address;
    }

Upvotes: 0

Views: 1527

Answers (1)

Christian Horsdal
Christian Horsdal

Reputation: 4932

You can model bind like this in your handler: var c = this.Bind<Client>();.

Here is the documentation: https://github.com/NancyFx/Nancy/wiki/Model-binding

Upvotes: 1

Related Questions