airship-0.9.1: A Webmachine-inspired HTTP library

Safe HaskellNone
LanguageHaskell2010

Airship.Helpers

Synopsis

Documentation

parseFormData :: Request -> IO ([Param], [File ByteString]) Source #

Parse form data uploaded with a Content-Type of either www-form-urlencoded or multipart/form-data to return a list of parameter names and values and a list of uploaded files and their information.

contentTypeMatches :: Monad m => [MediaType] -> Webmachine m Bool Source #

Returns True if the request's Content-Type header is one of the provided media types. If the Content-Type header is not present, this function will return True.

redirectTemporarily :: Monad m => ByteString -> Webmachine m a Source #

Issue an HTTP 302 (Found) response, with location as the destination.

redirectPermanently :: Monad m => ByteString -> Webmachine m a Source #

Issue an HTTP 301 (Moved Permantently) response, with location as the destination.

resourceToWai :: AirshipConfig -> RoutingSpec IO () -> ErrorResponses IO -> Application Source #

Given a RoutingSpec, a 404 resource, and a user state s, construct a WAI Application.

resourceToWaiT :: Monad m => AirshipConfig -> (AirshipRequest -> m Response -> IO Response) -> RoutingSpec m () -> ErrorResponses m -> Application Source #

Given a 'AirshipConfig, a function to modify the Response based on the AirshipRequest and the Response (like WAI middleware), a 'RoutingSpec, and ErrorResponses construct a WAI Application.

resourceToWaiT' :: Monad m => AirshipConfig -> (AirshipRequest -> m Response -> IO Response) -> Trie (RouteLeaf m) -> ErrorResponses m -> Application Source #

Like resourceToWaiT, but expects the RoutingSpec to have been evaluated with runRouter. This is more efficient than resourceToWaiT, as the routes will not be evaluated on every request.

Given routes :: RoutingSpec IO (), resourceToWaiT' can be invoked like so:

resourceToWaiT' cfg (const id) (runRouter routes) errors

lookupParam :: Monad m => Text -> Webmachine m Text Source #

Lookup routing parameter and return 500 Internal Server Error if not found. Not finding the paramter usually means the route doesn't match what the resource is expecting.

lookupParam' :: Monad m => Text -> Webmachine m (Maybe Text) Source #

Lookup routing parameter.