Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class HasServer layout where
- type Server layout = ServerT layout (ExceptT ServantErr IO)
- captured :: FromHttpApiData a => proxy (Capture sym a) -> Text -> Maybe a
- allowedMethodHead :: Method -> Request -> Bool
- allowedMethod :: Method -> Request -> Bool
- processMethodRouter :: forall a. ConvertibleStrings a ByteString => Maybe (a, ByteString) -> Status -> Method -> Maybe [(HeaderName, ByteString)] -> Request -> RouteResult Response
- methodCheck :: Method -> Request -> IO (RouteResult ())
- acceptCheck :: AllMime list => Proxy list -> ByteString -> IO (RouteResult ())
- methodRouter :: AllCTRender ctypes a => Method -> Proxy ctypes -> Status -> Delayed (ExceptT ServantErr IO a) -> Router
- methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v) => Method -> Proxy ctypes -> Status -> Delayed (ExceptT ServantErr IO (Headers h v)) -> Router
- methodRouterEmpty :: Method -> Delayed (ExceptT ServantErr IO ()) -> Router
- pathIsEmpty :: Request -> Bool
- ct_wildcard :: ByteString
- module Servant.Server.Internal.Router
- module Servant.Server.Internal.RoutingApplication
- module Servant.Server.Internal.ServantErr
Documentation
class HasServer layout where
type ServerT layout m :: *
HasServer * Raw | Just pass the request to the underlying application and serve its response. Example: type MyApi = "images" :> Raw server :: Server MyApi server = serveDirectory "/var/www/images" |
(HasServer * a, HasServer * b) => HasServer * ((:<|>) a b) | A server for type MyApi = "books" :> Get '[JSON] [Book] -- GET /books :<|> "books" :> ReqBody Book :> Post '[JSON] Book -- POST /books server :: Server MyApi server = listAllBooks :<|> postBook where listAllBooks = ... postBook book = ... |
(GetHeaders (Headers h v), AllCTRender ctypes v) => HasServer * (Get ctypes (Headers h v)) | |
HasServer * (Get ctypes ()) | |
AllCTRender ctypes a => HasServer * (Get ctypes a) | When implementing the handler for a If successfully returning a value, we use the type-level list, combined
with the request's |
(GetHeaders (Headers h v), AllCTRender ctypes v) => HasServer * (Post ctypes (Headers h v)) | |
HasServer * (Post ctypes ()) | |
AllCTRender ctypes a => HasServer * (Post ctypes a) | When implementing the handler for a If successfully returning a value, we use the type-level list, combined
with the request's |
(GetHeaders (Headers h v), AllCTRender ctypes v) => HasServer * (Delete ctypes (Headers h v)) | |
HasServer * (Delete ctypes ()) | |
AllCTRender ctypes a => HasServer * (Delete ctypes a) | If you have a The code of the handler will, just like
for |
(GetHeaders (Headers h v), AllCTRender ctypes v) => HasServer * (Put ctypes (Headers h v)) | |
HasServer * (Put ctypes ()) | |
AllCTRender ctypes a => HasServer * (Put ctypes a) | When implementing the handler for a If successfully returning a value, we use the type-level list, combined
with the request's |
(GetHeaders (Headers h v), AllCTRender ctypes v) => HasServer * (Patch ctypes (Headers h v)) | |
HasServer * (Patch ctypes ()) | |
AllCTRender ctypes a => HasServer * (Patch ctypes a) | When implementing the handler for a If successfully returning a value, we just require that its type has
a |
HasServer k api => HasServer * ((:>) * k HttpVersion api) | |
HasServer k api => HasServer * ((:>) * k Vault api) | |
HasServer k api => HasServer * ((:>) * k IsSecure api) | |
HasServer k api => HasServer * ((:>) * k RemoteHost api) | |
(AllCTUnrender list a, HasServer k sublayout) => HasServer * ((:>) * k (ReqBody * list a) sublayout) | If you use All it asks is for a Example: type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book server :: Server MyApi server = postBook where postBook :: Book -> ExceptT ServantErr IO Book postBook book = ...insert into your db... |
(KnownSymbol sym, HasServer k sublayout) => HasServer * ((:>) * k (QueryFlag sym) sublayout) | If you use Example: type MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book] server :: Server MyApi server = getBooks where getBooks :: Bool -> ExceptT ServantErr IO [Book] getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument... |
(KnownSymbol sym, FromHttpApiData a, HasServer k sublayout) => HasServer * ((:>) * k (QueryParams * 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 '[JSON] [Book] server :: Server MyApi server = getBooksBy where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book] getBooksBy authors = ...return all books by these authors... |
(KnownSymbol sym, FromHttpApiData a, HasServer k sublayout) => HasServer * ((:>) * k (QueryParam * 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 '[JSON] [Book] server :: Server MyApi server = getBooksBy where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book] getBooksBy Nothing = ...return all books... getBooksBy (Just author) = ...return books by the given author... |
(KnownSymbol sym, FromHttpApiData a, HasServer k sublayout) => HasServer * ((:>) * k (Header sym a) sublayout) | If you use All it asks is for a Example: newtype Referer = Referer Text deriving (Eq, Show, FromHttpApiData, ToText) -- GET /view-my-referer type MyApi = "view-my-referer" :> Header "Referer" Referer :> Get '[JSON] Referer server :: Server MyApi server = viewReferer where viewReferer :: Referer -> ExceptT ServantErr IO referer viewReferer referer = return referer |
(KnownSymbol capture, FromHttpApiData a, HasServer k sublayout) => HasServer * ((:>) * k (Capture * capture a) sublayout) | If you use You can control how it'll be converted from Example: type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book server :: Server MyApi server = getBook where getBook :: Text -> ExceptT ServantErr IO Book getBook isbn = ... |
(KnownSymbol path, HasServer k sublayout) => HasServer * ((:>) Symbol k path sublayout) | Make sure the incoming request starts with |
type Server layout = ServerT layout (ExceptT ServantErr IO)
Instances
allowedMethodHead :: Method -> Request -> Bool
allowedMethod :: Method -> Request -> Bool
processMethodRouter :: forall a. ConvertibleStrings a ByteString => Maybe (a, ByteString) -> Status -> Method -> Maybe [(HeaderName, ByteString)] -> Request -> RouteResult Response
methodCheck :: Method -> Request -> IO (RouteResult ())
acceptCheck :: AllMime list => Proxy list -> ByteString -> IO (RouteResult ())
methodRouter :: AllCTRender ctypes a => Method -> Proxy ctypes -> Status -> Delayed (ExceptT ServantErr IO a) -> Router
methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v) => Method -> Proxy ctypes -> Status -> Delayed (ExceptT ServantErr IO (Headers h v)) -> Router
methodRouterEmpty :: Method -> Delayed (ExceptT ServantErr IO ()) -> Router
pathIsEmpty :: Request -> Bool
ct_wildcard :: ByteString