Skip to content

Instantly share code, notes, and snippets.

@chamook
Created February 25, 2019 20:25
Show Gist options
  • Select an option

  • Save chamook/4f7fdb4a2257d6ae89027dfd2f374abf to your computer and use it in GitHub Desktop.

Select an option

Save chamook/4f7fdb4a2257d6ae89027dfd2f374abf to your computer and use it in GitHub Desktop.
let customJsonContentType mimeType data next (ctx : HttpContext) =
sprintf "%s; charset=utf-8" mimeType |> ctx.SetContentType
let serializer = ctx.GetJsonSerializer()
serializer.SerializeToBytes data
|> ctx.WriteBytesAsync
type CustomNegotiationConfig (baseConfig : INegotiationConfig) =
interface INegotiationConfig with
member __.UnacceptableHandler =
baseConfig.UnacceptableHandler
member __.Rules =
dict [
"*/*" , json
"application/json" , json
"application/vnd.chamook.mini-colours+json",
customJsonContentType "application/vnd.chamook.mini-colours+json"
]
let configureServices (services : IServiceCollection) =
services.AddGiraffe() |> ignore
CustomNegotiationConfig(DefaultNegotiationConfig())
|> services.AddSingleton<INegotiationConfig>
|> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment