named-servant-0.3.1: support records and named (from the named package) parameters in servant
Safe HaskellNone
LanguageHaskell2010

Servant.Record

Synopsis

Documentation

data RecordParam (a :: *) Source #

RecordParam uses the fields in the record to represent the parameters. The name of the field is used as parameter name, and the type is the return type. For example, this api:

type API = "users" :> (QueryParam "category" Category :>
                       QueryParam' '[Required, Strict] "sort_by" SortBy :>
                       QueryFlag "with_schema" :>
                       QueryParams "filters" Filter :>
                       Get '[JSON] User

can be written with records:

data UserParams = UserParams
  { category :: Maybe Category
  , sort_by :: Sortby
  , with_schema :: Bool
  , filters :: [Filter]
  }

type API = "users" :> RecordParam UserParams :> Get '[JSON] User

Instances

Instances details
(Generic a, GHasLink (Rep a) sub) => HasLink (RecordParam a :> sub :: Type) Source # 
Instance details

Defined in Servant.Record

Associated Types

type MkLink (RecordParam a :> sub) a #

Methods

toLink :: (Link -> a0) -> Proxy (RecordParam a :> sub) -> Link -> MkLink (RecordParam a :> sub) a0 #

type MkLink (RecordParam a :> sub :: Type) b Source # 
Instance details

Defined in Servant.Record

type MkLink (RecordParam a :> sub :: Type) b = a -> MkLink sub b

type family UnRecordParam (x :: *) :: * where ... Source #

Type family to rewrite a RecordParam Api to a regular servant API. Useful to define instances for classes that extract information from the API type, such as Servant.Swagger, or servant-foreign.

Typical use:

instance SomeClass (UnRecordParam (RecordParam a :> api))) =>
         SomeClass (RecordParam a :> api) where
   someMethod _ =
     someMethod (Proxy :: Proxy (UnRecordParam (RecordParam a :> api))

Equations

UnRecordParam (a :> b) = ServantAppend (UnRecordParam a) b 
UnRecordParam (RecordParam a) = UnRecordParam (Rep a ()) 
UnRecordParam (D1 m c d) = UnRecordParam (c d) 
UnRecordParam ((a :*: b) d) = ServantAppend (UnRecordParam (a d)) (UnRecordParam (b d)) 
UnRecordParam (C1 m a d) = UnRecordParam (a d) 
UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) d) = QueryFlag sym 
UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) d) = QueryParams sym a 
UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) d) = QueryParam' [Optional, Strict] sym a 
UnRecordParam (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) d) = QueryParam' [Required, Strict] sym a