Copyright | (c) Frederick Pringle 2024 |
---|---|
License | BSD-3-Clause |
Maintainer | freddyjepringle@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Simple term-level representation of Servant API endpoints.
Synopsis
- data Route
- defRoute :: Method -> Route
- showRoute :: Route -> Text
- routeMethod :: Lens' Route Method
- routePath :: Lens' Route Path
- routeParams :: Lens' Route [Param]
- routeRequestHeaders :: Lens' Route [HeaderRep]
- routeRequestBody :: Lens' Route Body
- routeResponseHeaders :: Lens' Route [HeaderRep]
- routeResponseType :: Lens' Route Body
- routeAuths :: Lens' Route [Text]
API routes
A simple representation of a single endpoint of an API.
The Route
type is not sophisticated, and its internals are hidden.
Create Route
s using defRoute
, and update its fields using the provided lenses.
showRoute :: Route -> Text Source #
Pretty-print a Route
. Note that the output is minimal and doesn't contain all the information
contained in a Route
. For full output, use the ToJSON
instance.
ghci> showRoute $ defRoute \"POST\" "POST /" ghci> :{ ghci| showRoute $ ghci| defRoute \"POST\" ghci| & routePath %~ prependPathPart "api/v2" ghci| & routeParams .~ [singleParam @"p1" @T.Text, flagParam @"flag", arrayElemParam @"p2s" @(Maybe Int)] ghci| :} "POST /api/v2?p1=<Text>&flag&p2s=<[Maybe Int]>"