GiraffeGenerator icon indicating copy to clipboard operation
GiraffeGenerator copied to clipboard

Support content type negotiation

Open bessgeor opened this issue 5 years ago • 0 comments

OpenAPI spec allows to define different types for different content types. It would be nice to generate something like that for this case:

type SomeMethodBodyInput =
  | SomeMethodBodyJson of SomeMethodJsonBodyInput
  | SomeMethodBodyFormUrlEncoded of SomeMethodFormUrlEncodedBodyInput
//...
match ctx.Request.Headers.ContentType with
| "text/json" ->
  let! json = ctx.bindJsonAsync<SomeMethodJsonBodyInput>()
  json
  //...
  |> SomeMethodBodyJson
  |> Ok
//...
| unsupported -> UnsupportedBodyContentType unsupported |> BodyBindingError |> Error

bessgeor avatar Oct 22 '20 12:10 bessgeor