tmcgilchrist / airship

Helium + Webmachine = Airship. A toolkit for building declarative, RESTful web apps.
http://tmcgilchrist.github.io/airship/
245 stars 14 forks source link

Question about Handler s m types on Resource #46

Closed tmcgilchrist closed 9 years ago

tmcgilchrist commented 9 years ago

This is more a query about the types of allowedMethods, contentTypesAccepted [1] and possibly contentTypesProvided. At the moment each of them is wrapped in a Handler s m a. I'm wondering why they can't just be say Bool or [(MediaType, Handler s m ())]. It doesn't seem like you'd want either of them to dynamic or perhaps I'm missing a use-case where you do.

We are thinking if they're not wrapped in Handler s m a we could generate nice API docs from each of the resources.

[1]https://github.com/helium/airship/blob/master/src/Airship/Resource.hs#L37-L46

reiddraper commented 9 years ago

Great question.

It doesn't seem like you'd want either of them to dynamic or perhaps I'm missing a use-case where you do.

Allowing them to be dynamic was exactly the rationale for putting them in this monad. For a trivial example, see the contentTypesProvided implementation of the static file resources. This needs to first look up the content-type from the 'state', before returning what content type is allowed on that particular path.

Another use-case would be implementing a CMS (content management system) where the entire application is database-driven.

reiddraper commented 9 years ago

Another example: imagine writing a resource where POST is only allowed the day that some new concert tickets are available.

tmcgilchrist commented 9 years ago

Thanks for the examples, makes sense.