TIL

Today I Learned


Project maintained by gushwell Hosted on GitHub Pages — Theme by mattgraham

Azure Functions で JSONを返す

    [FunctionName(nameof(V1Function))]
    public static async Task<HttpResponseMessage> V1Function(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "v1/SalesInference")] HttpRequest req,
        ILogger log) {
        ...
            
        var jsonToReturn = JsonConvert.SerializeObject(results,
            new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
        return new HttpResponseMessage(HttpStatusCode.OK) {
            Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
        };
    }

戻り値の型を、HttpResponseMessage とする。