Respond with both body and status code in Nancy

前端 未结 4 1699
花落未央
花落未央 2020-12-29 20:23

I\'m new to Nancy and I want to return both a custom HttpStatusCode and a body (content). If I return an HttpStatusCode, it returns it with a blank body. If I return a str

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 21:07

    This should work.

    public class SendSMS : NancyModule
    {
       public SendSMS()
       {
           Post["/SendSMS"] = parameters =>
           {
               return Negotiate.WithModel("Missing \"to\" param")
                               .WithStatusCode(HttpStatusCode.BadRequest)           
           };
       }
    } 
    

    For more information check the docs on controlling content negotiation.

提交回复
热议问题