Resolution Algorithms

note

Resolution Algorithms - 图1

This help topic is in development and will be updated in the future.

Routing is organized in a tree with a recursive matching system that is capable of handling quite complex rules for request processing. The Tree is built with nodes and selectors. The Node contains handlers and interceptors, and the selector is attached to an arc which connects another node. If selector matches current routing evaluation context, the algorithm goes down to the node associated with that selector.

Routing is built using a DSL in a nested manner:

  1. route("a") { // matches first segment with the value "a"
  2. route("b") { // matches second segment with the value "b"
  3. get {…} // matches GET verb, and installs a handler
  4. post {…} // matches POST verb, and installs a handler
  5. }
  6. }
  1. method(HttpMethod.Get) { // matches GET verb
  2. route("a") { // matches first segment with the value "a"
  3. route("b") { // matches second segment with the value "b"
  4. handle { } // installs handler
  5. }
  6. }
  7. }

Route resolution algorithms go through nodes recursively discarding subtrees where selector didn’t match.

Builder functions:

  • route(path) – adds path segments matcher(s)

  • method(verb) – adds HTTP method matcher.

  • param(name, value) – adds matcher for a specific value of the query parameter

  • param(name) – adds matcher that checks for the existence of a query parameter and captures its value

  • optionalParam(name) – adds matcher that captures the value of a query parameter if it exists

  • header(name, value) – adds matcher that for a specific value of HTTP header