register method

void register(
  1. String method,
  2. String pattern,
  3. RequestHandler handler
)

Register a request handler for any HTTP method with a pattern string.

Register a request handler to match a HTTP method and pattern.

Convenience methods for common HTTP methods exist: get, post, put, patch, delete. They simply invoke this method with corresponding values for the HTTP method.

This method is a convenience method that just converts the string representation of a pattern into a Pattern and then passes that object into registerPattern.

Throws an ArgumentError if the values are invalid (i.e. if the pattern string is not a valid pattern).

Throws a DuplicateRule if there is a conflict with an existing rule. A conflict is if Pattern.matchesSamePaths is true for the two patterns.

Null-safety breaking change: this method used to have a named parameter to use a Pattern instead of the string representation of a pattern. To register a rule using a Pattern object, use the registerPattern method instead.

Implementation

void register(String method, String pattern, RequestHandler handler) {
  final patternObj = Pattern(pattern); // can throw an ArgumentError

  registerPattern(method, patternObj, handler);
}