Representation of a static HTTP route.
Routes can be defined as simple maps or as more advanced structures. This module normalises external route specifications into a uniform internal form and provides matching helpers.
Summary
Functions
Deletes a route from the list using either :id or {method, path}.
Finds the first matching route and resolves its response specification.
Builds a route struct from a user-facing map specification.
Updates a route inside a route list using either :id or {method, path}.
Types
@type id() :: reference()
Unique route identifier.
@type t() :: %HttpDouble.Route{ body_match: nil | binary() | Regex.t(), header_matches: [{String.t(), String.t() | :any | Regex.t()}], host: String.t() | nil, id: id(), method: String.t(), path: String.t(), path_prefix: String.t() | nil, path_regex: Regex.t() | nil, query: %{optional(String.t()) => String.t() | :any}, response: HttpDouble.response_spec() }
Internal route representation.
Functions
Deletes a route from the list using either :id or {method, path}.
@spec find_match([t()], HttpDouble.Request.t()) :: {:ok, t(), HttpDouble.response_spec()} | :nomatch
Finds the first matching route and resolves its response specification.
Builds a route struct from a user-facing map specification.
Supported keys:
:method– string or atom, e.g. "GET" or :post:path– exact path match:path_prefix– prefix match:path_regex– regular expression:host– optional host match:query– map of query parameters, values can be exact strings or:any:headers– header match map or list of{name, value}(value can be string,:anyor regex):body– exact body match or regex:response– response specification (map,HttpDouble.Response, callback, etc.)
Updates a route inside a route list using either :id or {method, path}.