-
-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it easier to define more HTTP methods #190
Conversation
Caution: I haven't actually tried to use this yet (stack build had some issues in the other projects about disabled components) so it's possible the entire idea is unworkable. |
data Delete (contentTypes :: [*]) a | ||
deriving Typeable | ||
|
||
type Delete (contentTypes :: [*]) a = HttpMethod "DELETE" 200 contentTypes a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doctest should say Delete <content-type> ()
(our mistake - only now are the doctests failing here because previously it'd still compile)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I got quite confused starting out because the documentation says you can use Delete
without arguments in a few places.
Great idea, by the way. Thanks! |
Had a think about how to achieve #189 :
This should continue to have backwards compatibility while allowing more flexibility in status codes. I'll write this up after work today and see how it goes. |
I haven't been following along but any change I feel should allow the user to provide a status code. Regardless of what the specs say in case someone wants to provide a custome status code they should be able to. Is that where this is going? |
|
||
import Data.Typeable (Typeable) | ||
import GHC.TypeLits (Nat, Symbol) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some documentation saying you can use this to define your own status code response/method?
Looks great. This changes the behaviour of methods to not return 204 when the type is Otherwise (and aside from the small comment), this looks good to me. |
I'm really not sure about this. How wrong would it be to not give 204 when appropriate, but e.g 200 instead? Would it mess things up with external tools? Would it annoy people? |
@jkarni the intention is to not remove special-casing 204 for |
This factors out common functionality from the HasServer instances for the various existing HTTP methods, so that there is only one real datatype (HttpMethod) and the existing implementations are all just type aliases. This should hopefully make it near-trivial to define new HTTP methods.
Instead we use a type family to set this, where it's needed (for backwards compatibility).
|
||
type ServerT (Put ctypes a) m = m a | ||
type ServerT (HttpMethod method ctypes (ServantSuccess a)) m = m (ServantSuccess a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. Another option maybe worth discussing is just putting in a StateT
in the midst of the stack with the status code (initialized to 200 for GET, 201 for POST, 204 for ()
, etc.). In theory I guess we could then even remove the EitherT
then (and have users themselves declare sum types when they may return very different datatypes. That would be a pretty fundamental change, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, thinking more on it, I think we want to go in the direction of making HTTP status codes more rather than less knowable statically. (And the handlers less rather than more HTTP-aware.)
@Porges I like the type synonyms, but I'm not so sure about EDIT: Or make this PR just about the type synonyms, and then open an issue for discussion of |
Sorry about lack of movement on this - my personal laptop deaded itself and I haven't replaced it yet... |
Closing in favour of #276 (and thanks!) |
Sending this for a bit of discussion.
This change factors out common functionality from the HasServer instances for
the various existing HTTP methods, so that there is only one real
datatype (
HttpMethod
) and the existing implementations are all just typealiases for this.
This should hopefully make it near-trivial to define new HTTP methods.
I think this should be mostly source-compatible with the previous implementation?
Probably need to do something about the 'default' status codes as well (per #189).