Skip to content

Commit 99356af

Browse files
committed
Update changelog
1 parent 91426aa commit 99356af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

changelog.d/1561

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
synopsis: New combinator to return routed path in response headers
2+
prs: #1561
3+
4+
description: {
5+
6+
This commit introduces a new type-level combinator, `WithRoutingHeader`.
7+
It modifies the behaviour of the following sub-API, such that all endpoints of said API return an additional routing header in their response.
8+
9+
A routing header is a header that specifies which endpoint the incoming request was routed to.
10+
Endpoint are designated by their path, in which `Capture'` and `CaptureAll` combinators are replaced by a capture hint.
11+
12+
This header can be used by downstream middlewares to gather information about individual endpoints, since in most cases
13+
a routing header uniquely identifies a single endpoint.
14+
15+
Example:
16+
17+
```haskell
18+
type MyApi =
19+
WithRoutingHeader :> "by-id" :> Capture "id" Int :> Get '[JSON] Foo
20+
-- GET /by-id/1234 will return a response with the following header:
21+
-- ("Servant-Routed-Path", "/by-id/<id:CaptureSingle>")
22+
```
23+
24+
To achieve this, two refactorings were necessary:
25+
26+
* 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.
27+
* 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)`.
28+
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).
29+
30+
This PR also introduces `Spec` tests for the `WithRoutingHeader` combinator, which showcase some of its possible uses.
31+
32+
}

0 commit comments

Comments
 (0)