-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Composable, type-safe library to build HTTP API servers -- -- WebGear is a library to for building composable, type-safe HTTP API -- servers. WebGear focuses on good documentation and usability. See the -- documentation of WebGear module to get started. @package webgear-server @version 0.2.0 module WebGear.Modifiers -- | Modifier used to indicate whether a trait is required or optional. data Existence Required :: Existence Optional :: Existence -- | Modifier used to indicate whether a trait is parsed strictly or -- leniently. data ParseStyle Strict :: ParseStyle Lenient :: ParseStyle -- | Traits are optional attributes associated with a value. For example, a -- list containing totally ordered values might have a Maximum -- trait where the associated attribute is the maximum value. This trait -- exists only if the list is non-empty. The Trait typeclass -- provides an interface to extract such trait attributes. -- -- Traits help to link attributes with values in a type-safe manner. -- -- Traits are somewhat similar to refinement types, but allow -- arbitrary attributes to be associated with a value instead of only a -- predicate. module WebGear.Trait -- | A trait is an optional attribute t associated with a value -- a. class Monad m => Trait t a m where { -- | Type of the associated attribute when the trait holds for a value type family Attribute t a :: Type; -- | Type that indicates that the trait does not exist for a value. This -- could be an error message, parse error etc. type family Absence t a :: Type; } -- | Attempt to deduce the trait attribute from the value a. It is -- possible that deducing a trait's presence can alter the value, hence -- this function returns a possibly updated value along with the trait -- attribute on success. toAttribute :: Trait t a m => a -> m (Result t a) -- | The result of toAttribute - either a successful deduction of an -- attribute or an error. data Result t a NotFound :: Absence t a -> Result t a Found :: Attribute t a -> Result t a -- | A value linked with a type-level list of traits. data Linked (ts :: [Type]) a -- | Wrap a value with an empty list of traits. link :: a -> Linked '[] a -- | Retrive the value from a linked value unlink :: Linked ts a -> a -- | Attempt to link an additional trait with an already linked value via -- the toAttribute operation. This can fail indicating an -- Absence of the trait. probe :: forall t ts a m. Trait t a m => Linked ts a -> m (Either (Absence t a) (Linked (t : ts) a)) -- | Remove the leading trait from the type-level list of traits remove :: Linked (t : ts) a -> Linked ts a -- | Constraint that proves that the trait t is present in the -- list of traits ts. class Has t ts -- | Get the attribute associated with t from a linked value get :: Has t ts => Proxy t -> Linked ts a -> Attribute t a -- | Constraint that proves that all the traits in the list ts are -- also present in the list qs. type family Have ts qs :: Constraint -- | Type error for nicer UX of missing traits type MissingTrait t = Text "The request doesn't have the trait \8216" :<>: ShowType t :<>: Text "\8217." :$$: Text "" :$$: Text "Did you use a wrong trait type?" :$$: Text "For e.g., \8216PathVar \"foo\" Int\8217 instead of \8216PathVar \"foo\" String\8217?" :$$: Text "" :$$: Text "Or did you forget to apply an appropriate middleware?" :$$: Text "For e.g. The trait \8216JSONRequestBody Foo\8217 can be used with \8216jsonRequestBody @Foo\8217 middleware." :$$: Text "" instance forall k (t :: k). (TypeError ...) => WebGear.Trait.Has t '[] instance WebGear.Trait.Has t (t : ts) instance forall k (t :: k) (ts :: [*]) t'. WebGear.Trait.Has t ts => WebGear.Trait.Has t (t' : ts) instance GHC.Base.Monad m => WebGear.Trait.Trait '[] a m instance forall a1 (t :: a1) a2 (m :: * -> *) (ts :: [a1]). (WebGear.Trait.Trait t a2 m, WebGear.Trait.Trait ts a2 m, GHC.Base.Monad m) => WebGear.Trait.Trait (t : ts) a2 m -- | Common types and functions used throughout WebGear. module WebGear.Types -- | Information on the request sent by the client. This abstracts away the -- details of the underlying implementation. data Request -- | The client's host information. remoteHost :: Request -> SockAddr -- | HTTP version such as 1.1. httpVersion :: Request -> HttpVersion -- | Was this request made over an SSL connection? -- -- Note that this value will not tell you if the client originally -- made this request over SSL, but rather whether the current connection -- is SSL. The distinction lies with reverse proxies. In many cases, the -- client will connect to a load balancer over SSL, but connect to the -- WAI handler without SSL. In such a case, isSecure will be -- False, but from a user perspective, there is a secure -- connection. isSecure :: Request -> Bool -- | Request method such as GET. requestMethod :: Request -> Method -- | Path info in individual pieces - the URL without a hostname/port and -- without a query string, split on forward slashes. pathInfo :: Request -> [Text] -- | Parsed query string information. queryString :: Request -> Query -- | Get the value of a request header requestHeader :: HeaderName -> Request -> Maybe ByteString -- | A list of headers (a pair of key and value) in an HTTP request. requestHeaders :: Request -> RequestHeaders -- | The size of the request body. In the case of a chunked request body, -- this may be unknown. -- -- Since 1.4.0 requestBodyLength :: Request -> RequestBodyLength -- | Get the next chunk of the body. Returns empty when the body is -- fully consumed. getRequestBodyChunk :: Request -> IO ByteString -- | An HTTP response sent from the server to the client. -- -- The response contains a status, optional headers and an optional body -- of type a. data Response a Response :: Status -> HashMap HeaderName ByteString -> Maybe a -> Response a -- | Response status code [responseStatus] :: Response a -> Status -- | Response headers [responseHeaders] :: Response a -> HashMap HeaderName ByteString -- | Optional response body [responseBody] :: Response a -> Maybe a -- | Looks up a response header responseHeader :: HeaderName -> Response a -> Maybe ByteString -- | Set a response header value setResponseHeader :: HeaderName -> ByteString -> Response a -> Response a -- | Convert a WebGear response to a WAI Response. waiResponse :: Response ByteString -> Response -- | Create a response with a given status and body respond :: Status -> Maybe a -> Response a -- | Continue 100 response continue100 :: Response a -- | Switching Protocols 101 response switchingProtocols101 :: Response a -- | OK 200 response ok200 :: a -> Response a -- | Created 201 response created201 :: a -> Response a -- | Accepted 202 response accepted202 :: a -> Response a -- | Non-Authoritative 203 response nonAuthoritative203 :: a -> Response a -- | No Content 204 response noContent204 :: Response a -- | Reset Content 205 response resetContent205 :: Response a -- | Partial Content 206 response partialContent206 :: a -> Response a -- | Multiple Choices 300 response multipleChoices300 :: a -> Response a -- | Moved Permanently 301 response movedPermanently301 :: a -> Response a -- | Found 302 response found302 :: a -> Response a -- | See Other 303 response seeOther303 :: a -> Response a -- | Not Modified 304 response notModified304 :: Response a -- | Temporary Redirect 307 response temporaryRedirect307 :: a -> Response a -- | Permanent Redirect 308 response permanentRedirect308 :: a -> Response a -- | Bad Request 400 response badRequest400 :: a -> Response a -- | Unauthorized 401 response unauthorized401 :: a -> Response a -- | Payment Required 402 response paymentRequired402 :: a -> Response a -- | Forbidden 403 response forbidden403 :: a -> Response a -- | Not Found 404 response notFound404 :: Response a -- | Method Not Allowed 405 response methodNotAllowed405 :: a -> Response a -- | Not Acceptable 406 response notAcceptable406 :: a -> Response a -- | Proxy Authentication Required 407 response proxyAuthenticationRequired407 :: a -> Response a -- | Request Timeout 408 response requestTimeout408 :: a -> Response a -- | Conflict 409 response conflict409 :: a -> Response a -- | Gone 410 response gone410 :: a -> Response a -- | Length Required 411 response lengthRequired411 :: a -> Response a -- | Precondition Failed 412 response preconditionFailed412 :: a -> Response a -- | Request Entity Too Large 413 response requestEntityTooLarge413 :: a -> Response a -- | Request URI Too Long 414 response requestURITooLong414 :: a -> Response a -- | Unsupported Media Type 415 response unsupportedMediaType415 :: a -> Response a -- | Requested Range Not Satisfiable 416 response requestedRangeNotSatisfiable416 :: a -> Response a -- | Expectation Failed 417 response expectationFailed417 :: a -> Response a -- | I'm A Teapot 418 response imATeapot418 :: a -> Response a -- | Unprocessable Entity 422 response unprocessableEntity422 :: a -> Response a -- | Precondition Required 428 response preconditionRequired428 :: a -> Response a -- | Too Many Requests 429 response tooManyRequests429 :: a -> Response a -- | Request Header Fields Too Large 431 response requestHeaderFieldsTooLarge431 :: a -> Response a -- | Internal Server Error 500 response internalServerError500 :: a -> Response a -- | Not Implemented 501 response notImplemented501 :: a -> Response a -- | Bad Gateway 502 response badGateway502 :: a -> Response a -- | Service Unavailable 503 response serviceUnavailable503 :: a -> Response a -- | Gateway Timeout 504 response gatewayTimeout504 :: a -> Response a -- | HTTP Version Not Supported 505 response httpVersionNotSupported505 :: a -> Response a -- | Network Authentication Required 511 response networkAuthenticationRequired511 :: a -> Response a -- | A handler is a function from a request to response in a monadic -- context. Both the request and the response can have linked traits. -- -- The type level list req contains all the traits expected to -- be present in the request. type Handler' m req a = Kleisli m (Linked req Request) (Response a) -- | A handler that runs on the Router monad. type Handler req a = Handler' Router req a -- | A middleware takes a handler as input and produces another handler -- that usually adds some functionality. -- -- A middleware can do a number of things with the request handling such -- as: -- --
-- queryParam @"limit" @Int handler ---- -- The associated trait attribute has type val. This middleware -- will respond with a 400 Bad Request response if the query parameter is -- not found or could not be parsed. queryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam name val : req) a -- | A middleware to extract an optional query parameter and convert it to -- a value of type val using FromHttpApiData. -- -- Example usage: -- --
-- optionalQueryParam @"limit" @Int handler ---- -- The associated trait attribute has type Maybe val; a -- Nothing value indicates a missing param. A 400 Bad Request -- response is returned if the query parameter could not be parsed. optionalQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Optional Strict name val : req) a -- | A middleware to extract a query parameter and convert it to a value of -- type val using FromHttpApiData. -- -- Example usage: -- --
-- lenientQueryParam @"limit" @Int handler ---- -- The associated trait attribute has type Either Text val. A -- 400 Bad Request reponse is returned if the query parameter is missing. -- The parsing is done leniently; the trait attribute is set to Left -- Text in case of parse errors or Right val on success. lenientQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Required Lenient name val : req) a -- | A middleware to extract an optional query parameter and convert it to -- a value of type val using FromHttpApiData. -- -- Example usage: -- --
-- optionalLenientHeader @"Content-Length" @Integer handler ---- -- The associated trait attribute has type Maybe (Either Text -- val). This middleware never fails. optionalLenientQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Optional Lenient name val : req) a instance GHC.Classes.Eq WebGear.Middlewares.Params.ParamParseError instance GHC.Show.Show WebGear.Middlewares.Params.ParamParseError instance GHC.Read.Read WebGear.Middlewares.Params.ParamParseError instance GHC.Classes.Eq WebGear.Middlewares.Params.ParamNotFound instance GHC.Show.Show WebGear.Middlewares.Params.ParamNotFound instance GHC.Read.Read WebGear.Middlewares.Params.ParamNotFound instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Params.QueryParam' 'WebGear.Modifiers.Required 'WebGear.Modifiers.Strict name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Params.QueryParam' 'WebGear.Modifiers.Optional 'WebGear.Modifiers.Strict name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Params.QueryParam' 'WebGear.Modifiers.Required 'WebGear.Modifiers.Lenient name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Params.QueryParam' 'WebGear.Modifiers.Optional 'WebGear.Modifiers.Lenient name val) Network.Wai.Internal.Request m -- | Middlewares related to HTTP methods. module WebGear.Middlewares.Method -- | A Trait for capturing the HTTP method of a request data Method (t :: StdMethod) -- | A typeclass to map a StdMethod from type level to term level. class IsStdMethod t -- | Convert t to term level. toStdMethod :: IsStdMethod t => Proxy t -> StdMethod -- | Failure to match method against an expected value data MethodMismatch MethodMismatch :: Method -> Method -> MethodMismatch [expectedMethod] :: MethodMismatch -> Method [actualMethod] :: MethodMismatch -> Method -- | A middleware to check whether the request has a specified HTTP method. -- -- Typically this would be used with a type application such as: -- --
-- method @GET handler ---- -- It is also idiomatic to use the template haskell quasiquoter -- match in cases where both HTTP method and path needs to be -- matched. method :: forall t m req a. (IsStdMethod t, MonadRouter m) => RequestMiddleware' m req (Method t : req) a instance (WebGear.Middlewares.Method.IsStdMethod t, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Method.Method t) Network.Wai.Internal.Request m instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.GET instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.POST instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.HEAD instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.PUT instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.DELETE instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.TRACE instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.CONNECT instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.OPTIONS instance WebGear.Middlewares.Method.IsStdMethod 'Network.HTTP.Types.Method.PATCH -- | Middlewares related to HTTP headers. module WebGear.Middlewares.Header -- | A Trait for capturing a header with name name in a -- request or response and convert it to some type val via -- FromHttpApiData. type Header (name :: Symbol) (val :: Type) = Header' Required Strict name val -- | A Trait for capturing an HTTP header of specified name -- and converting it to some type val via -- FromHttpApiData. The modifiers e and p -- determine how missing headers and parsing errors are handled. The -- header name is compared case-insensitively. data Header' (e :: Existence) (p :: ParseStyle) (name :: Symbol) (val :: Type) -- | Indicates a missing header data HeaderNotFound HeaderNotFound :: HeaderNotFound -- | Error in converting a header newtype HeaderParseError HeaderParseError :: Text -> HeaderParseError -- | A Trait for ensuring that a header with a specified -- name has value val. type HeaderMatch (name :: Symbol) (val :: Symbol) = HeaderMatch' Required name val -- | A Trait for ensuring that an HTTP header with specified -- name has value val. The modifier e -- determines how missing headers are handled. The header name is -- compared case-insensitively. data HeaderMatch' (e :: Existence) (name :: Symbol) (val :: Symbol) -- | Failure in extracting a header value data HeaderMismatch HeaderMismatch :: ByteString -> ByteString -> HeaderMismatch [expectedHeader] :: HeaderMismatch -> ByteString [actualHeader] :: HeaderMismatch -> ByteString -- | A middleware to extract a header value and convert it to a value of -- type val using FromHttpApiData. -- -- Example usage: -- --
-- header @"Content-Length" @Integer handler ---- -- The associated trait attribute has type val. A 400 Bad -- Request response is returned if the header is not found or could not -- be parsed. header :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (Header name val : req) a -- | A middleware to extract a header value and convert it to a value of -- type val using FromHttpApiData. -- -- Example usage: -- --
-- optionalHeader @"Content-Length" @Integer handler ---- -- The associated trait attribute has type Maybe val; a -- Nothing value indicates that the header is missing from the -- request. A 400 Bad Request response is returned if the header could -- not be parsed. optionalHeader :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (Header' Optional Strict name val : req) a -- | A middleware to extract a header value and convert it to a value of -- type val using FromHttpApiData. -- -- Example usage: -- --
-- lenientHeader @"Content-Length" @Integer handler ---- -- The associated trait attribute has type Either Text val. A -- 400 Bad Request reponse is returned if the header is missing. The -- parsing is done leniently; the trait attribute is set to Left -- Text in case of parse errors or Right val on success. lenientHeader :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (Header' Required Lenient name val : req) a -- | A middleware to extract an optional header value and convert it to a -- value of type val using FromHttpApiData. -- -- Example usage: -- --
-- optionalLenientHeader @"Content-Length" @Integer handler ---- -- The associated trait attribute has type Maybe (Either Text -- val). This middleware never fails. optionalLenientHeader :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (Header' Optional Lenient name val : req) a -- | A middleware to ensure that a header in the request has a specific -- value. Fails the handler with a 400 Bad Request response if the header -- does not exist or does not match. headerMatch :: forall name val m req a. (KnownSymbol name, KnownSymbol val, MonadRouter m) => RequestMiddleware' m req (HeaderMatch name val : req) a -- | A middleware to ensure that an optional header in the request has a -- specific value. Fails the handler with a 400 Bad Request response if -- the header has a different value. optionalHeaderMatch :: forall name val m req a. (KnownSymbol name, KnownSymbol val, MonadRouter m) => RequestMiddleware' m req (HeaderMatch' Optional name val : req) a -- | A middleware to check that the Content-Type header in the request has -- a specific value. It will fail the handler if the header did not -- match. -- -- Example usage: -- --
-- requestContentTypeHeader @"application/json" handler --requestContentTypeHeader :: forall val m req a. (KnownSymbol val, MonadRouter m) => RequestMiddleware' m req (HeaderMatch "Content-Type" val : req) a -- | A middleware to create or update a response header. -- -- Example usage: -- --
-- addResponseHeader "Content-type" "application/json" handler --addResponseHeader :: forall t m req a. (ToHttpApiData t, Monad m) => HeaderName -> t -> ResponseMiddleware' m req a a instance GHC.Show.Show WebGear.Middlewares.Header.HeaderMismatch instance GHC.Read.Read WebGear.Middlewares.Header.HeaderMismatch instance GHC.Classes.Eq WebGear.Middlewares.Header.HeaderMismatch instance GHC.Classes.Eq WebGear.Middlewares.Header.HeaderParseError instance GHC.Show.Show WebGear.Middlewares.Header.HeaderParseError instance GHC.Read.Read WebGear.Middlewares.Header.HeaderParseError instance GHC.Classes.Eq WebGear.Middlewares.Header.HeaderNotFound instance GHC.Show.Show WebGear.Middlewares.Header.HeaderNotFound instance GHC.Read.Read WebGear.Middlewares.Header.HeaderNotFound instance (GHC.TypeLits.KnownSymbol name, GHC.TypeLits.KnownSymbol val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.HeaderMatch' 'WebGear.Modifiers.Required name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, GHC.TypeLits.KnownSymbol val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.HeaderMatch' 'WebGear.Modifiers.Optional name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Required 'WebGear.Modifiers.Strict name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Optional 'WebGear.Modifiers.Strict name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Required 'WebGear.Modifiers.Strict name val) (WebGear.Types.Response a) m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Optional 'WebGear.Modifiers.Strict name val) (WebGear.Types.Response a) m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Required 'WebGear.Modifiers.Lenient name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Required 'WebGear.Modifiers.Lenient name val) (WebGear.Types.Response a) m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Optional 'WebGear.Modifiers.Lenient name val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val, GHC.Base.Monad m) => WebGear.Trait.Trait (WebGear.Middlewares.Header.Header' 'WebGear.Modifiers.Optional 'WebGear.Modifiers.Lenient name val) (WebGear.Types.Response a) m -- | Middlewares related to route paths. module WebGear.Middlewares.Path -- | A path component which is literally matched against the request but -- discarded after that. data Path (s :: Symbol) -- | A path variable that is extracted and converted to a value of type -- val. The tag is usually a type-level symbol (string) -- to uniquely identify this variable. data PathVar tag val -- | Failure to extract a PathVar data PathVarError PathVarNotFound :: PathVarError PathVarParseError :: Text -> PathVarError -- | Trait to indicate that no more path components are present in the -- request data PathEnd -- | A middleware that literally matches path s. -- -- The symbol s could contain one or more parts separated by a -- forward slash character. The route will be rejected if there is no -- match. -- -- For example, the following code could be used to match the URL path -- "a/b/c" and then invoke handler: -- --
-- path @"a/b/c" handler --path :: forall s ts m a. (KnownSymbol s, MonadRouter m) => RequestMiddleware' m ts (Path s : ts) a -- | A middleware that captures a path variable from a single path -- component. -- -- The value captured is converted to a value of type val via -- FromHttpApiData. The route will be rejected if the value is not -- found or cannot be converted. -- -- For example, the following code could be used to read a path component -- as Int tagged with the symbol "objId", and then invoke -- handler: -- --
-- pathVar @"objId" @Int handler --pathVar :: forall tag val ts m a. (FromHttpApiData val, MonadRouter m) => RequestMiddleware' m ts (PathVar tag val : ts) a -- | A middleware that verifies that end of path is reached. pathEnd :: MonadRouter m => RequestMiddleware' m ts (PathEnd : ts) a -- | Produces middleware(s) to match an optional HTTP method and some path -- components. -- -- This middleware matches a prefix of path components, the remaining -- components can be matched by subsequent uses of match. -- -- This quasiquoter can be used in several ways: -- -- TODO: table match :: QuasiQuoter -- | Produces middleware(s) to match an optional HTTP method and the entire -- request path. -- -- This middleware is intended to be used in cases where the entire path -- needs to be matched. Use match middleware to match only an -- initial portion of the path. -- -- This quasiquoter can be used in several ways: -- -- TODO: table route :: QuasiQuoter instance GHC.Read.Read WebGear.Middlewares.Path.PathVarError instance GHC.Show.Show WebGear.Middlewares.Path.PathVarError instance GHC.Classes.Eq WebGear.Middlewares.Path.PathVarError instance Control.Monad.State.Class.MonadState WebGear.Types.PathInfo m => WebGear.Trait.Trait WebGear.Middlewares.Path.PathEnd Network.Wai.Internal.Request m instance forall k val (m :: * -> *) (tag :: k). (Web.Internal.HttpApiData.FromHttpApiData val, Control.Monad.State.Class.MonadState WebGear.Types.PathInfo m) => WebGear.Trait.Trait (WebGear.Middlewares.Path.PathVar tag val) Network.Wai.Internal.Request m instance (GHC.TypeLits.KnownSymbol s, Control.Monad.State.Class.MonadState WebGear.Types.PathInfo m) => WebGear.Trait.Trait (WebGear.Middlewares.Path.Path s) Network.Wai.Internal.Request m -- | Middlewares related to HTTP body. module WebGear.Middlewares.Body -- | A Trait for converting a JSON request body into a value. data JSONRequestBody (t :: Type) -- | A middleware to parse the request body as JSON and convert it to a -- value via a FromJSON instance. -- -- Usage for a type t which has a FromJSON instance: -- --
-- jsonRequestBody @t handler ---- -- Returns a 400 Bad Request response on failure to parse body. jsonRequestBody :: forall t m req a. (FromJSON t, MonadRouter m, MonadIO m) => RequestMiddleware' m req (JSONRequestBody t : req) a -- | A middleware that converts the response that has a ToJSON -- instance to a ByteString response. -- -- This will also set the "Content-Type" header of the response to -- "application/json". -- -- Usage for a type t which has a ToJSON instance: -- --
-- jsonResponseBody @t handler --jsonResponseBody :: (ToJSON t, Monad m) => ResponseMiddleware' m req t ByteString instance (Data.Aeson.Types.FromJSON.FromJSON t, Control.Monad.IO.Class.MonadIO m) => WebGear.Trait.Trait (WebGear.Middlewares.Body.JSONRequestBody t) Network.Wai.Internal.Request m -- | Basic authentication support. module WebGear.Middlewares.Auth.Basic -- | Trait for HTTP basic authentication: -- https://tools.ietf.org/html/rfc7617 data BasicAuth -- | The protection space for basic authentication newtype Realm Realm :: ByteString -> Realm -- | Username for basic authentication. Valid usernames cannot contain ':' -- characters. newtype Username Username :: ByteString -> Username -- | Password for basic authentication. newtype Password Password :: ByteString -> Password -- | Basic authentication credentials retrieved from an HTTP request data Credentials Credentials :: !Username -> !Password -> Credentials [credentialsUsername] :: Credentials -> !Username [credentialsPassword] :: Credentials -> !Password -- | Error extracting credentials from an HTTP request data BasicAuthError -- | Authorization header is missing or badly formatted AuthHeaderError :: BasicAuthError -- | Authorization scheme is not Basic AuthSchemeMismatch :: BasicAuthError -- | Middleware to add basic authentication protection for a handler. -- -- Example usage: -- --
-- basicAuth "realm" isValidCredentials handler ---- -- This middleware returns a 401 response if no credentials are found in -- the request. It returns a 403 response if credentials are present but -- isValidCredentials returns False. basicAuth :: forall m req a. MonadRouter m => Realm -> (Credentials -> m Bool) -> RequestMiddleware' m req (BasicAuth : req) a instance GHC.Read.Read WebGear.Middlewares.Auth.Basic.BasicAuthError instance GHC.Show.Show WebGear.Middlewares.Auth.Basic.BasicAuthError instance GHC.Classes.Ord WebGear.Middlewares.Auth.Basic.BasicAuthError instance GHC.Classes.Eq WebGear.Middlewares.Auth.Basic.BasicAuthError instance GHC.Read.Read WebGear.Middlewares.Auth.Basic.Credentials instance GHC.Show.Show WebGear.Middlewares.Auth.Basic.Credentials instance GHC.Classes.Ord WebGear.Middlewares.Auth.Basic.Credentials instance GHC.Classes.Eq WebGear.Middlewares.Auth.Basic.Credentials instance Data.String.IsString WebGear.Middlewares.Auth.Basic.Password instance GHC.Read.Read WebGear.Middlewares.Auth.Basic.Password instance GHC.Show.Show WebGear.Middlewares.Auth.Basic.Password instance GHC.Classes.Ord WebGear.Middlewares.Auth.Basic.Password instance GHC.Classes.Eq WebGear.Middlewares.Auth.Basic.Password instance Data.String.IsString WebGear.Middlewares.Auth.Basic.Username instance GHC.Read.Read WebGear.Middlewares.Auth.Basic.Username instance GHC.Show.Show WebGear.Middlewares.Auth.Basic.Username instance GHC.Classes.Ord WebGear.Middlewares.Auth.Basic.Username instance GHC.Classes.Eq WebGear.Middlewares.Auth.Basic.Username instance Data.String.IsString WebGear.Middlewares.Auth.Basic.Realm instance GHC.Read.Read WebGear.Middlewares.Auth.Basic.Realm instance GHC.Show.Show WebGear.Middlewares.Auth.Basic.Realm instance GHC.Classes.Ord WebGear.Middlewares.Auth.Basic.Realm instance GHC.Classes.Eq WebGear.Middlewares.Auth.Basic.Realm instance GHC.Base.Monad m => WebGear.Trait.Trait WebGear.Middlewares.Auth.Basic.BasicAuth Network.Wai.Internal.Request m -- | Middlewares provided by WebGear. module WebGear.Middlewares -- | WebGear helps to build composable, type-safe HTTP API servers. -- -- The documentation below gives an overview of WebGear. Example programs -- built using WebGear are available at -- https://github.com/rkaippully/webgear/tree/master/webgear-examples. module WebGear