Functions for defining HTTP routes.
Represents an HTTP route.
get : String -> HttpRoute
Define a GET route with the given URL.
get "http://fun.com/fun"
post : String -> HttpRoute
Define a POST route with the given URL.
post "http://fun.com/fun"
Describe a URL when constructing a Route with the route
function.
Use the Exact
case when you want to provide a specific string to match against, for example, an absolute URL.
Use the Matching
case when you want to provide a JavaScript-style regular expression to match against.
route : String -> UrlDescriptor -> HttpRoute
Define a route with the given method and url descriptor.
For example, this route describes any request with the
protocol http
and the method PATCH
:
Spec.Http.Route.route "PATCH" <|
Matching "http:\\/\\/.+"
And this route describes any GET
request to http://someplace.com/api
with any value
for the query parameter key
(and any additional query parameters):
Spec.Http.Route.route "GET" <|
Matching "http:\\/\\/someplace\\.com\\/api\\?key=.+"
encode : HttpRoute -> Json.Encode.Value
Encode an HttpRoute
into a JSON object.
toString : HttpRoute -> String
Represent an HttpRoute
as a string.