| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.API.Sub
Documentation
data path :> a infixr 9 Source
The contained API (second argument) can be found under ("/" ++ path)
(path being the first argument).
Example:
-- GET /hello/world -- returning a JSON encoded World value type MyApi = "hello" :> "world" :> Get World
Instances
| (KnownSymbol s, VLinkHelper * e) => VLinkHelper * ((:>) Symbol s e) | |
| (KnownSymbol capture, FromText a, HasServer sublayout) => HasServer ((:>) * (Capture Symbol * capture a) sublayout) | If you use You can control how it'll be converted from Example: type MyApi = "books" :> Capture "isbn" Text :> Get Book
server :: Server MyApi
server = getBook
where getBook :: Text -> EitherT (Int, String) IO Book
getBook isbn = ... |
| (KnownSymbol sym, FromText a, HasServer sublayout) => HasServer ((:>) * (Header Symbol * sym a) sublayout) | If you use All it asks is for a Example: newtype Referer = Referer Text
deriving (Eq, Show, FromText, ToText)
-- GET /view-my-referer
type MyApi = "view-my-referer" :> Header "Referer" Referer :> Get Referer
server :: Server MyApi
server = viewReferer
where viewReferer :: Referer -> EitherT (Int, String) IO referer
viewReferer referer = return referer |
| (KnownSymbol sym, HasServer sublayout) => HasServer ((:>) * (QueryFlag Symbol sym) sublayout) | If you use Example: type MyApi = "books" :> QueryFlag "published" :> Get [Book]
server :: Server MyApi
server = getBooks
where getBooks :: Bool -> EitherT (Int, String) IO [Book]
getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument... |
| (KnownSymbol sym, FromText a, HasServer sublayout) => HasServer ((:>) * (QueryParams Symbol * sym a) sublayout) | If you use This lets servant worry about looking up 0 or more values in the query string
associated to You can control how the individual values are converted from Example: type MyApi = "books" :> QueryParams "authors" Text :> Get [Book]
server :: Server MyApi
server = getBooksBy
where getBooksBy :: [Text] -> EitherT (Int, String) IO [Book]
getBooksBy authors = ...return all books by these authors... |
| (KnownSymbol sym, FromText a, HasServer sublayout) => HasServer ((:>) * (QueryParam Symbol * sym a) sublayout) | If you use This lets servant worry about looking it up in the query string
and turning it into a value of the type you specify, enclosed
in You can control how it'll be converted from Example: type MyApi = "books" :> QueryParam "author" Text :> Get [Book]
server :: Server MyApi
server = getBooksBy
where getBooksBy :: Maybe Text -> EitherT (Int, String) IO [Book]
getBooksBy Nothing = ...return all books...
getBooksBy (Just author) = ...return books by the given author... |
| (FromJSON a, HasServer sublayout) => HasServer ((:>) * (ReqBody * a) sublayout) | If you use All it asks is for a Example: type MyApi = "books" :> ReqBody Book :> Post Book
server :: Server MyApi
server = postBook
where postBook :: Book -> EitherT (Int, String) IO Book
postBook book = ...insert into your db... |
| (KnownSymbol path, HasServer sublayout) => HasServer ((:>) Symbol path sublayout) | Make sure the incoming request starts with |
| type Server ((:>) * (Capture Symbol * capture a) sublayout) = a -> Server sublayout | |
| type Server ((:>) * (Header Symbol * sym a) sublayout) = Maybe a -> Server sublayout | |
| type Server ((:>) * (QueryFlag Symbol sym) sublayout) = Bool -> Server sublayout | |
| type Server ((:>) * (QueryParams Symbol * sym a) sublayout) = [a] -> Server sublayout | |
| type Server ((:>) * (QueryParam Symbol * sym a) sublayout) = Maybe a -> Server sublayout | |
| type Server ((:>) * (ReqBody * a) sublayout) = a -> Server sublayout | |
| type Server ((:>) Symbol path sublayout) = Server sublayout |