servant/servant
Nicolas BACQUEY 9ccb5afa9f New combinator to return routed path in response headers
This commit introduces a new type-level combinator, `WithRoutingHeader`.
It modifies the behaviour of the following sub-API, such that all endpoint
of said API return an additional routing header in their response.

A routing header is a header that specifies which endpoint the
incoming request was routed to.

Endpoint are designated by their path, in which `Capture'` and
`CaptureAll` combinators are replaced by a capture hint.

This header can be used by downstream middlewares to gather
information about individual endpoints, since in most cases
a routing header uniquely identifies a single endpoint.

Example:
```haskell
type MyApi =
  WithRoutingHeader :> "by-id" :> Capture "id" Int :> Get '[JSON] Foo
-- GET /by-id/1234 will return a response with the following header:
--   ("Servant-Routed-Path", "/by-id/<id::Int>")
```

To achieve this, two refactorings were necessary:
* Introduce a type `RouterEnv env` to encapsulate the `env` type
  (as in `Router env a`), which contains a tuple-encoded list of url
  pieces parsed from the incoming request.
  This type makes it possible to pass more information throughout the
  routing process, and the computation of the `Delayed env c` associated
  with each request.
* Introduce a new kind of router, which only modifies the RouterEnv, and
  doesn't affect the routing process otherwise.
  `EnvRouter (RouterEnv env -> RouterEnv env) (Router' env a)`
  This new router is used when encountering the `WithRoutingHeader`
  combinator in an API, to notify the endpoints of the sub-API that they
  must produce a routing header (this behaviour is disabled by default).
2022-04-19 14:04:22 +02:00
..
src/Servant New combinator to return routed path in response headers 2022-04-19 14:04:22 +02:00
test Support GHC-9.0.1 2021-06-23 23:06:07 +02:00
.ghci add servant/.ghci 2016-01-07 23:59:54 +01:00
CHANGELOG.md Fix NamedRoutes example in 0.19 changelog (#1523) 2022-02-03 09:56:19 +01:00
docs.sh prepare merge 2015-04-20 11:21:21 +02:00
LICENSE Changelog and cabal file edits 2018-11-13 09:58:42 +02:00
servant.cabal New combinator to return routed path in response headers 2022-04-19 14:04:22 +02:00
Setup.hs Change build-type: Simple; run doctests on CI via haskell-ci 2020-01-10 01:07:31 +02:00
update-nixpkgs.sh prepare merge 2015-04-20 11:21:21 +02:00