Returning a string containing valid Json with Nancy

后端 未结 5 634
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 14:05

I receive a string that contains valid JSON from another service. I would like to just forward this string with Nancy but also set the content-type to \"application/json\" which

5条回答
  •  耶瑟儿~
    2021-01-31 14:59

    If all routes of your module return a JSON string, then you can set the content type in the After hook for all routes at once:

    Get["/"] = _ =>
    {
        // ... 
        return myJsonString;
    };
    
    After += ctx =>
    {
        ctx.Response.ContentType = "application/json";
    };
    

提交回复
热议问题