liveBook · Manning

Route

As explained in F# in Action: A Revised Edition of Get Programming with F#

A route is a web-application rule that associates request properties such as an HTTP method and URI path with a handler.

A route connects request properties to a web-application handler. In practice, an HTTP method and path such as GET and /device/status select the behavior that produces the response. section 13.2.3

Giraffe treats route matching as an HTTP handler that can be composed with method filters and response handlers. This replaces manual branching with a short, uniform pipeline. section 13.2.3 section 13.2.4

A status endpoint

GET >=> route "/device/status" >=> text "device is operating correctly" composes a method check, path match, and text response. Visiting the endpoint returns the expected status message. section 13.2.3

Compose several routes with choose when an application exposes multiple endpoints:

  • GET >=> route "/device/status" handles status requests. section 13.2.4
  • POST >=> route "/device/execute" handles command requests. section 13.2.4
  • choose tries handlers in order and returns the first successful match. section 13.2.4
GET >=> route "/device/status" >=> text "device is operating correctly"

Inspect the compact Giraffe pipeline combining an HTTP method, route, and response handler. section 13.2.3

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Implements route matching and composition, including parameterized and regular-expression variants, without detailing router internals.
Examples
Uses GET /device/status for a status response and POST /device/execute for command execution.
What it assumes
Assumes HTTP handlers and verbs, while demonstrating route matching through small Giraffe pipelines.
What you can do after
Apply it via Giraffe to compose method checks, path matches, and response handlers into endpoints.
How it connects
Connects HTTP handlers, HTTP methods, URI paths, response handlers, and choose-based composition.

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.