I like that you think there should be a better way, because you need to use 3 lines of code, I think something is saying about Nancy :-)
I can't think of a โbetterโ way to do this, you can either do it with the GetBytes method:
Get["/"] = _ => { var jsonBytes = Encoding.UTF8.GetBytes(myJsonString); return new Response { ContentType = "application/json", Contents = s => s.Write(jsonBytes, 0, jsonBytes.Length) }; };
Or the way to "distinguish a string":
Get["/"] = _ => { var response = (Response)myJsonString; response.ContentType = "application/json"; return response; };
Both do the same thing - the last less code, the first more descriptive (imo).
Steven Robbins Sep 30 '11 at 12:05 2011-09-30 12:05
source share