Package spark.route

Class Routes

java.lang.Object
spark.route.Routes
Direct Known Subclasses:
SimpleRouteMatcher

public class Routes extends Object
Holds the routes and performs matching from HTTP requests to routes. Works as Sinatra's, ie. if there are more than one match the one that was mapped first is chosen.
Author:
Per Wendel
  • Constructor Details

    • Routes

      protected Routes()
      Constructor
  • Method Details

    • create

      public static Routes create()
    • add

      public void add(HttpMethod httpMethod, RouteImpl route)
      Add a route
      Parameters:
      httpMethod - the http-method of the route
      route - the route to add
    • add

      public void add(HttpMethod httpMethod, FilterImpl filter)
      Add a filter
      Parameters:
      httpMethod - the http-method of the route
      filter - the filter to add
    • find

      public RouteMatch find(HttpMethod httpMethod, String path, String acceptType)
      finds target for a requested route
      Parameters:
      httpMethod - the http method
      path - the path
      acceptType - the accept type
      Returns:
      the target
    • findMultiple

      public List<RouteMatch> findMultiple(HttpMethod httpMethod, String path, String acceptType)
      Finds multiple targets for a requested route.
      Parameters:
      httpMethod - the http method
      path - the route path
      acceptType - the accept type
      Returns:
      the targets
    • findAll

      public List<RouteMatch> findAll()
      Returns:
      the targets
    • clear

      public void clear()
      ¨Clear all routes
    • remove

      public boolean remove(String path, String httpMethod)
      Removes a particular route from the collection of those that have been previously routed. Search for a previously established routes using the given path and HTTP method, removing any matches that are found.
      Parameters:
      path - the route path
      httpMethod - the http method
      Returns:
      true if this a matching route has been previously routed
      Throws:
      IllegalArgumentException - if path is null or blank or if httpMethod is null, blank or an invalid HTTP method
      Since:
      2.2
    • remove

      public boolean remove(String path)
      Removes a particular route from the collection of those that have been previously routed. Search for a previously established routes using the given path and removes any matches that are found.
      Parameters:
      path - the route path
      Returns:
      true if this a matching route has been previously routed
      Throws:
      IllegalArgumentException - if path is null or blank
      Since:
      2.2
    • add

      @Deprecated public void add(String route, String acceptType, Object target)
      Deprecated.
      Parse and validates a route and adds it
      Parameters:
      route - the route path
      acceptType - the accept type
      target - the invocation target