Analyzer::Gleam::Wisp
Inherits Analyzer < FileHelper < Reference < Object
Wisp has no route table — routing is a case over the split path,
and the verb comes either from a second subject in the same case or
from the handler it delegates to. All four shapes are common in real
apps:
case wisp.path_segments(req) { # path only
["users", id] -> user(req, id)
}
case wisp.path_segments(req), req.method { # path, method
["api", "teams"], http.Post -> create_team(req)
}
case req.method, wisp.path_segments(req) { # method, path
Get, ["members"] -> members.list(req)
}
let path = wisp.path_segments(req) # via let bindings
let method = req.method
case method, path {
Get, [] -> home.render(req)
}
Rather than assume an order, the subject is parsed to learn which
comma position holds the path and which holds the method, and each
arm is then read against those positions. When the arm carries no
verb the handler it calls is followed (resolve_handler) to find a
case req.method or a wisp.require_method.
Constants
Verbs that can carry a request body.
list.key_find(formdata.values, "title") — the binder is named
formdata, form, … so match any receiver.
2-arg request.get_header(req, "accept") and the piped 1-arg
|> request.get_header("accept") are both idiomatic.
Calls into the standard library and wisp itself are responses and helpers, never route handlers.
A wisp.require_json body is decoded elsewhere; decode.field is
where the field names actually appear.
Depth limit for following a route arm through handler functions to
the case req.method that names its verb.
A case subject spans at most a handful of lines even when the
formatter wraps it.
_ -> wisp.method_not_allowed([Get, Post]) and
_, _ -> wisp.not_found() are the fallthrough arms every wisp
router ends with. They match a path but serve no endpoint.
let path = wisp.path_segments(req) / let method = req.method.
Apps that bind these before the case would otherwise leave the
subject looking like two bare identifiers.
Class methods
Instance methods
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.