我想知道如何为压缩的REST调用返回JSON:
GET /orders HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
但是文档只谈论返回文件
let setJson it =
it
|>JsonUtils.toJson
|> OK
>=> setMimeType "application/json; charset=utf-8"
let doReq route request action =
path route >=> setCORSHeaders >=> request (fun r -> action(r) |> setJson)
doReq "/orders" request (fun r -> queryOrders(r |> getTerm, Products.Name))
答案 0 :(得分:1)
我相信可以通过添加新的MIME类型并为第二个参数传递true
来在MIME类型映射中进行配置,例如:
let mimeTypes =
defaultMimeTypesMap
@@ (function | ".json" -> createMimeType "application/json" true | _ -> None)
let webConfig = { defaultConfig with mimeTypesMap = mimeTypes }
this page中记录了MIME类型和压缩的配置。