hello! I’m playing a bit with http4k and typesafe ...
# http4k
g
hello! I’m playing a bit with http4k and typesafe contracts and I’m wondering how we can define response headers in the API definition. It seems like we can only define http status codes + content body, the headers seem to be skipped somehow.
Copy code
returning(
  ResponseMeta(
    description = "Created successfully",
    response = Response(Status.CREATED).header("Location", "/api/v1/orders/${UUID.randomUUID()}"),
  )
)
it properly identifies the response & also the status code, but it kind of ignores the
Location
header in the API definition. is it something I’m missing? is there another way to tell http4k contracts I’m returning a specific header so it can add to the openapi definition? thanks in advance! 🙂
Taking a look at
org.http4k.contract.openapi.v3.ResponseContents
, it seems that we only consider the description & the body content, not the headers. I may send a PR trying to also support headers for
OpenApi3
d
you're not missing anything - at the moment, only request headers are currently supported in the http4k-contract module.
g
thanks for your answer, @dave. I’m working on a PR already. The only problem is that the Response headers are based on simple string to string tuples, so it lacks of information about the actual type & the description of the header. does it make sense to send a PR initially with headers as strings? at least we would support headers in the api definition, later on it could be improved to also support the description & the actual type of the headers.
d
I'm not sure what you mean about "Response headers are based on simple string to string tuples," - in what context do you mean? It would be fairly simple to follow the existing pattern that we already have for request headers I think 🙂 - but I could be mistaken if I have misunderstood