As in previous answers, there is no support for binding directly to a dynamic type, the most similar is the ModelBinder provided by TheCodeJunkie at https://gist.github.com/thecodejunkie/5521941
However, this approach has a problem and lies in the fact that the DynamicDictionary obtained as a result of this code does not order later, producing only dictionary keys and losing values. This is described here. Why does storing Nancy.DynamicDictionary in RavenDB save property names, not property values? and today (version 1.4.3) is still happening, seriously limiting this approach.
The solution is to use a simple trick, access to the raw data received in POST, and deserialize using JSON.Net. In your example, this would be:
using System; using System.Dynamic; using Nancy; using Nancy.Extensions; using Newtonsoft.Json; Post["/apiurl"] = p => { dynamic obj = JsonConvert.DeserializeObject<ExpandoObject>(Request.Body.AsString());
Note that you need to use Nancy.Extensions to call Request.Body.AsString ().
maki
source share