liveBook · Manning

Capture

As explained in Learn Haskell by Example

Capture is a Servant combinator that declares a typed variable segment captured from an endpoint route.

Capture is a Servant combinator for declaring a typed variable segment in an endpoint route. When a route matches, Servant passes the captured value to the endpoint implementation. section 17.1.1

Capturing a route value

The API type `"select" :> Capture "id" String :> Get '[JSON] SomeType` matches `/select/this` and passes `this` to the implementation. Capture can use other types too, such as `Int` in a todo-list toggle route. section 17.1.1

How Learn Haskell by Example covers it

How deep it goes
Explains the combinator through route examples, but does not show handler implementation details.
Examples
Uses `/select/this` with a String capture and a todo-list `/toggle` route with an Int capture.
What you can do after
Apply it via Servant to pass a matched route segment into an endpoint implementation.
How it connects
Connects endpoint routes with Servant implementations, HTTP GET handlers, and typed route parameters.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.