mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00
Make routing constraints use the fields format
This makes routing more in line with the rest of Cowboy and allows us to use cowboy_constraints directly.
This commit is contained in:
parent
f1c3b6d76f
commit
25259671f5
3 changed files with 36 additions and 70 deletions
|
@ -191,26 +191,16 @@ HostMatch = "*".
|
|||
After the matching has completed, the resulting bindings can be tested
|
||||
against a set of constraints. Constraints are only tested when the
|
||||
binding is defined. They run in the order you defined them. The match
|
||||
will succeed only if they all succeed.
|
||||
will succeed only if they all succeed. If the match fails, then Cowboy
|
||||
tries the next route in the list.
|
||||
|
||||
They are always given as a two or three elements tuple, where the first
|
||||
element is the name of the binding, the second element is the constraint's
|
||||
name, and the optional third element is the constraint's arguments.
|
||||
The format used for constraints is the same as match functions in
|
||||
`cowboy_req`: they are provided as a list of fields which may have
|
||||
one or more constraints. While the router accepts the same format,
|
||||
it will skip fields with no constraints and will also ignore default
|
||||
values, if any.
|
||||
|
||||
The following constraints are currently defined:
|
||||
|
||||
* {Name, int}
|
||||
* {Name, function, fun ((Value) -> true | {true, NewValue} | false)}
|
||||
|
||||
The `int` constraint will check if the binding is a binary string
|
||||
representing an integer, and if it is, will convert the value to integer.
|
||||
|
||||
The `function` constraint will pass the binding value to a user specified
|
||||
function that receives the binary value as its only argument and must
|
||||
return whether it fulfills the constraint, optionally modifying the value.
|
||||
The value thus returned can be of any type.
|
||||
|
||||
Note that constraint functions SHOULD be pure and MUST NOT crash.
|
||||
Read more about ^constraints^.
|
||||
|
||||
:: Compilation
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue