Get url parameters in NancyFx

前端 未结 3 660
粉色の甜心
粉色の甜心 2021-02-06 21:46

I am using NancyFx to build a web API, but I am facing some problems when getting parameters from the URL.

I need to send, to the API, the request .../consumptions

3条回答
  •  青春惊慌失措
    2021-02-06 22:34

    You can let NancyFx's model binding take care of the url query string.

    public class RequestObject 
    {
        public string Granularity { get; set; }
        public long From { get; set; }
        public long To { get; set; }
    }
    

    /consumptions/hourly?from=1402012800000&to=1402099199000

    Get["consumptions/{granularity}"] = x =>
    {
        var request = this.Bind();
    }
    

提交回复
热议问题