mig-0.2.1.0: Build lightweight and composable servers
Safe HaskellSafe-Inferred
LanguageGHC2021

Mig.Core.Types.Route

Description

Newtype wrappers for route DSL

Synopsis

inputs

newtype Body media a Source #

Generic case for request body. The type encodes a media type and value of the request body.

Constructors

Body a 

Instances

Instances details
(FromReqBody ty a, ToSchema a, ToPlugin b) => ToPlugin (Body ty a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

Methods

toPluginInfo :: RouteInfo -> RouteInfo Source #

toPluginFun :: (Body ty a -> b) -> ServerFun (MonadOf (Body ty a -> b)) -> ServerFun (MonadOf (Body ty a -> b)) Source #

(ToSchema a, FromReqBody media a, ToRoute b) => ToRoute (Body media a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

Methods

toRouteInfo :: RouteInfo -> RouteInfo Source #

toRouteFun :: (Body media a -> b) -> ServerFun (MonadOf (Body media a -> b)) Source #

newtype Query (sym :: Symbol) a Source #

Required URL parameter query.

"api/route?foo=bar" ==> (Query bar) :: Query "foo" a

Constructors

Query a 

Instances

Instances details
(FromHttpApiData a, ToParamSchema a, ToPlugin b, KnownSymbol sym) => ToPlugin (Query sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

Methods

toPluginInfo :: RouteInfo -> RouteInfo Source #

toPluginFun :: (Query sym a -> b) -> ServerFun (MonadOf (Query sym a -> b)) -> ServerFun (MonadOf (Query sym a -> b)) Source #

(FromHttpApiData a, ToParamSchema a, ToRoute b, KnownSymbol sym) => ToRoute (Query sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

Methods

toRouteInfo :: RouteInfo -> RouteInfo Source #

toRouteFun :: (Query sym a -> b) -> ServerFun (MonadOf (Query sym a -> b)) Source #

(KnownSymbol sym, ToHttpApiData a, ToUrl b) => ToUrl (Query sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Query sym a -> b Source #

mapUrl :: (Url -> Url) -> (Query sym a -> b) -> Query sym a -> b Source #

urlArity :: Int Source #

newtype QueryFlag (sym :: Symbol) Source #

Query flag. It is a boolean value in the URL-query. If it is missing it is False if it is in the query but does not have any value it is True. Also it can have values true/false in the query.

Constructors

QueryFlag Bool 

Instances

Instances details
(ToPlugin b, KnownSymbol sym) => ToPlugin (QueryFlag sym -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

(ToRoute b, KnownSymbol sym) => ToRoute (QueryFlag sym -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

(KnownSymbol sym, ToUrl b) => ToUrl (QueryFlag sym -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> QueryFlag sym -> b Source #

mapUrl :: (Url -> Url) -> (QueryFlag sym -> b) -> QueryFlag sym -> b Source #

urlArity :: Int Source #

newtype Optional (sym :: Symbol) a Source #

Optional URL parameter query.

"api/route?foo=bar" ==> (Optional maybeBar) :: Query "foo" a

Constructors

Optional (Maybe a) 

Instances

Instances details
(FromHttpApiData a, ToParamSchema a, ToPlugin b, KnownSymbol sym) => ToPlugin (Optional sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

Methods

toPluginInfo :: RouteInfo -> RouteInfo Source #

toPluginFun :: (Optional sym a -> b) -> ServerFun (MonadOf (Optional sym a -> b)) -> ServerFun (MonadOf (Optional sym a -> b)) Source #

(FromHttpApiData a, ToParamSchema a, ToRoute b, KnownSymbol sym) => ToRoute (Optional sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

Methods

toRouteInfo :: RouteInfo -> RouteInfo Source #

toRouteFun :: (Optional sym a -> b) -> ServerFun (MonadOf (Optional sym a -> b)) Source #

(KnownSymbol sym, ToHttpApiData a, ToUrl b) => ToUrl (Optional sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Optional sym a -> b Source #

mapUrl :: (Url -> Url) -> (Optional sym a -> b) -> Optional sym a -> b Source #

urlArity :: Int Source #

newtype Capture (sym :: Symbol) a Source #

Argument of capture from the query.

"api/route/{foo} if api/route/bar passed"  ==> (Capture bar) :: Capture "Foo" barType

Constructors

Capture a 

Instances

Instances details
(FromHttpApiData a, ToParamSchema a, ToPlugin b, KnownSymbol sym) => ToPlugin (Capture sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

Methods

toPluginInfo :: RouteInfo -> RouteInfo Source #

toPluginFun :: (Capture sym a -> b) -> ServerFun (MonadOf (Capture sym a -> b)) -> ServerFun (MonadOf (Capture sym a -> b)) Source #

(FromHttpApiData a, ToParamSchema a, ToRoute b, KnownSymbol sym) => ToRoute (Capture sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

Methods

toRouteInfo :: RouteInfo -> RouteInfo Source #

toRouteFun :: (Capture sym a -> b) -> ServerFun (MonadOf (Capture sym a -> b)) Source #

(KnownSymbol sym, ToHttpApiData a, ToUrl b) => ToUrl (Capture sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Url

Methods

toUrl :: forall (m :: Type -> Type). Server m -> Capture sym a -> b Source #

mapUrl :: (Url -> Url) -> (Capture sym a -> b) -> Capture sym a -> b Source #

urlArity :: Int Source #

newtype Header (sym :: Symbol) a Source #

Reads value from the required header by name. For example if the request has header:

"foo": "bar"

It reads the value:

(Header bar) :: Header "foo" barType

Constructors

Header a 

Instances

Instances details
(FromHttpApiData a, ToParamSchema a, ToPlugin b, KnownSymbol sym) => ToPlugin (Header sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

Methods

toPluginInfo :: RouteInfo -> RouteInfo Source #

toPluginFun :: (Header sym a -> b) -> ServerFun (MonadOf (Header sym a -> b)) -> ServerFun (MonadOf (Header sym a -> b)) Source #

(FromHttpApiData a, ToParamSchema a, ToRoute b, KnownSymbol sym) => ToRoute (Header sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

Methods

toRouteInfo :: RouteInfo -> RouteInfo Source #

toRouteFun :: (Header sym a -> b) -> ServerFun (MonadOf (Header sym a -> b)) Source #

newtype OptionalHeader (sym :: Symbol) a Source #

Reads value from the optional header by name. For example if the request has header:

"foo": "bar"

It reads the value:

(OptionalHeader (Just bar)) :: OptionalHeader "foo" barType

Constructors

OptionalHeader (Maybe a) 

Instances

Instances details
(FromHttpApiData a, ToParamSchema a, ToPlugin b, KnownSymbol sym) => ToPlugin (OptionalHeader sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

(FromHttpApiData a, ToParamSchema a, ToRoute b, KnownSymbol sym) => ToRoute (OptionalHeader sym a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

newtype Cookie a Source #

Reads a cookie. It's an optional header with name Cookie. The cookie is URL-encoded and read with instnace of FromForm class.

data MyCookie = MyCookie
  { secret :: Text
  , count :: Int
  }
  deriving (Generic, FromForm)

> "secret=lolkek&count=101"

(Cookie (Just (MyCookie { secret = "lolkek", count = 101 }))) :: Cookie MyCookie

Constructors

Cookie (Maybe a) 

Instances

Instances details
(FromForm a, ToPlugin b) => ToPlugin (Cookie a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

(FromForm a, ToRoute b) => ToRoute (Cookie a -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

newtype PathInfo Source #

Reads current path info.

"api/foo/bar" ==> PathInfo ["foo", "bar"]

Constructors

PathInfo [Text] 

Instances

Instances details
ToPlugin a => ToPlugin (PathInfo -> a) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

ToRoute b => ToRoute (PathInfo -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

newtype FullPathInfo Source #

Reads current full-path info with queries.

"api/foo/bar?param=value" ==> FullPathInfo "api/foo/bar?param=value"

Constructors

FullPathInfo Text 

Instances

Instances details
ToPlugin a => ToPlugin (FullPathInfo -> a) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

ToRoute b => ToRoute (FullPathInfo -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

newtype RawRequest Source #

Read low-level request. Note that it does not affect the API schema

Constructors

RawRequest Request 

Instances

Instances details
ToPlugin a => ToPlugin (RawRequest -> a) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

ToRoute b => ToRoute (RawRequest -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

newtype IsSecure Source #

Reads info on weather the connection is secure (made over SSL).

Constructors

IsSecure Bool 

Instances

Instances details
ToPlugin a => ToPlugin (IsSecure -> a) Source # 
Instance details

Defined in Mig.Core.Class.Plugin

ToRoute b => ToRoute (IsSecure -> b) Source # 
Instance details

Defined in Mig.Core.Class.Route

outputs

newtype Send method m a Source #

Route response type. It encodes the route method in the type and which monad is used and which type the response has.

The repsonse value is usually one of two cases:

  • Resp media a -- for routes which always produce a value
  • RespOr media err a - for routes that can also produce an error or value.

See the class IsResp for more details on response types.

Constructors

Send 

Fields

Instances

Instances details
MonadTrans (Send method :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Mig.Core.Types.Route

Methods

lift :: Monad m => m a -> Send method m a #

MonadIO m => MonadIO (Send method m) Source # 
Instance details

Defined in Mig.Core.Types.Route

Methods

liftIO :: IO a -> Send method m a #

Applicative m => Applicative (Send method m) Source # 
Instance details

Defined in Mig.Core.Types.Route

Methods

pure :: a -> Send method m a #

(<*>) :: Send method m (a -> b) -> Send method m a -> Send method m b #

liftA2 :: (a -> b -> c) -> Send method m a -> Send method m b -> Send method m c #

(*>) :: Send method m a -> Send method m b -> Send method m b #

(<*) :: Send method m a -> Send method m b -> Send method m a #

Functor m => Functor (Send method m) Source # 
Instance details

Defined in Mig.Core.Types.Route

Methods

fmap :: (a -> b) -> Send method m a -> Send method m b #

(<$) :: a -> Send method m b -> Send method m a #

Monad m => Monad (Send method m) Source # 
Instance details

Defined in Mig.Core.Types.Route

Methods

(>>=) :: Send method m a -> (a -> Send method m b) -> Send method m b #

(>>) :: Send method m a -> Send method m b -> Send method m b #

return :: a -> Send method m a #

(MonadIO m, IsResp a, IsMethod method) => ToRoute (Send method m a) Source # 
Instance details

Defined in Mig.Core.Class.Route

Methods

toRouteInfo :: RouteInfo -> RouteInfo Source #

toRouteFun :: Send method m a -> ServerFun (MonadOf (Send method m a)) Source #

type Get m a = Send GET m a Source #

Get request

type Post m a = Send POST m a Source #

Post request

type Put m a = Send PUT m a Source #

Put request

type Delete m a = Send DELETE m a Source #

Delete request

type Options m a = Send OPTIONS m a Source #

Options request

type Head m a = Send HEAD m a Source #

Head request

type Patch m a = Send PATCH m a Source #

Path request

type Trace m a = Send TRACE m a Source #

trace request

Method tags

class IsMethod a where Source #

Converts type-level tag for methods to value

Instances

Instances details
IsMethod DELETE Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod GET Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod HEAD Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod OPTIONS Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod PATCH Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod POST Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod PUT Source # 
Instance details

Defined in Mig.Core.Types.Route

IsMethod TRACE Source # 
Instance details

Defined in Mig.Core.Types.Route

data GET Source #

type-level GET-method tag

Instances

Instances details
IsMethod GET Source # 
Instance details

Defined in Mig.Core.Types.Route

data POST Source #

type-level POST-method tag

Instances

Instances details
IsMethod POST Source # 
Instance details

Defined in Mig.Core.Types.Route

data PUT Source #

type-level PUT-method tag

Instances

Instances details
IsMethod PUT Source # 
Instance details

Defined in Mig.Core.Types.Route

data DELETE Source #

type-level DELETE-method tag

Instances

Instances details
IsMethod DELETE Source # 
Instance details

Defined in Mig.Core.Types.Route

data OPTIONS Source #

type-level OPTIONS-method tag

Instances

Instances details
IsMethod OPTIONS Source # 
Instance details

Defined in Mig.Core.Types.Route

data HEAD Source #

type-level HEAD-method tag

Instances

Instances details
IsMethod HEAD Source # 
Instance details

Defined in Mig.Core.Types.Route

data PATCH Source #

type-level PATCH-method tag

Instances

Instances details
IsMethod PATCH Source # 
Instance details

Defined in Mig.Core.Types.Route

data TRACE Source #

type-level TRACE-method tag

Instances

Instances details
IsMethod TRACE Source # 
Instance details

Defined in Mig.Core.Types.Route