Copyright | (c) Frederick Pringle 2025 |
---|---|
License | BSD-3-Clause |
Maintainer | frederick.pringle@fpringle.com |
Safe Haskell | None |
Language | Haskell2010 |
Servant.API.Routes.Route
Contents
Description
Simple term-level representation of Servant API endpoints.
Synopsis
- data Route
- defRoute :: Method -> Route
- renderRoute :: Route -> Text
- routeMethod :: Lens' Route Method
- routePath :: Lens' Route Path
- routeParams :: Lens' Route (Set Param)
- routeRequestHeaders :: Lens' Route (Set HeaderRep)
- routeRequestBody :: Lens' Route Request
- routeResponse :: Lens' Route Responses
- routeAuths :: Lens' Route (Set Auth)
- routeDescription :: Lens' Route (Maybe RouteDescription)
- routeSummary :: Lens' Route (Maybe RouteSummary)
- add :: Ord a => ASetter s t (Set a) (Set a) -> a -> s -> t
- newtype RouteDescription = RouteDescription {}
- newtype RouteSummary = RouteSummary {}
API routes
The Route
type is not sophisticated, and its internals are hidden.
Create Route
s using defRoute
, and update its fields
using the provided lenses.
A simple representation of a single endpoint of an API.
renderRoute :: 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> renderRoute $ defRoute \"POST\" "POST /" ghci> :{ ghci| renderRoute $ 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]>"
Optics
Auxiliary types
newtype RouteDescription Source #
Description of a route. This will correspond to the Servant Description
combinator.
It should be noted that the HasRoutes
behaviour for Description
diverges from that in
servant-openapi3
, in the case that one EP has multiple Description
combinators.
For example, given the following API:
type MyAPI = "transaction" :> TransactionAPI :<|> "user" :> Description "User sub-API" :> ( Description "Get my user" :> Get '[JSON] User :<|> "list" :> Get '[JSON] [User] )
The Operation
that servant-openapi
generates for the GET /user
endpoint will have the two
Description
s mappend
-ed together: "User sub-APIGet my user"
.
The corresponding Route
will take the most specific RouteDescription
: "Get my user"
.
Constructors
RouteDescription | |
Fields |
Instances
newtype RouteSummary Source #
Short summary of a route. This will correspond to the Servant Summary
combinator.
The behaviour described for RouteDescription
is the same for RouteSummary
.
Constructors
RouteSummary | |