haskell-servant / servant

Servat is a Haskell DSL for describing, serving, querying, mocking, documenting web applications and more!
https://docs.servant.dev/
1.83k stars 414 forks source link

NoContent and Accept #1067

Open MichaelXavier opened 5 years ago

MichaelXavier commented 5 years ago

If I'm understanding correctly, it seems that if you're creating an endpoint that does not take a body, NoContent would be an appropricate content type to use since you can't use an empty list. However, NoContent does not have any sensible Accept instance, nor a reasonable MimeUnrender. For MimeUnrender, it seems clear that an instance for () which always succeeds would be appropriate. However, for Accept, there is isn't really a nullary mime type to indicate nothing. The specs seem to indicate that Accept is optional but that clients should assume the endpoint accepts both text/plain and text/html.

So the question:

  1. Would you accept a PR implementing instance MimeUnrender NoContent ()?
  2. What should we do about accept? It seems like the semantically correct thing is to make Accept not require a specific mime type since it isn't required. The pragmatic approach that would disturb less code would seem to be to accept text/plain and text/html for NoContent as per the spec's rules about defaulting, possibly at the cost of producing a confusing Accept.
alpmestan commented 5 years ago

@phadej Thoughts?

phadej commented 5 years ago

I think #969 will solve some issues:

For now, I'd try if we can have an OVERLAPPING instance for Verb ... NoContent, which won't perform accept-check. I was pretty sure we had it already.