Interface Filter

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Filter
Something that sees every request before the route does.

Authentication, rate limiting, a header on every response. A filter either calls what comes next or answers instead, which is what makes refusing a request possible.

 Router.create()
 	.use((request, path, env, ctx, next) -> {
 		if (!"secret".equals(request.header("authorization"))) {
 			return Bytebox.response("no", 401);
 		}
 		return next.get();
 	})
 	.get("/private", Api::secret);
Since:
1.0.0
  • Method Details

    • filter

      Response filter(Request request, Map<String,String> path, Env env, ExecutionCtx ctx, Supplier<Response> next)
      Sees the request.
      Parameters:
      request - the request
      path - what the matched pattern captured
      env - the bindings
      ctx - the invocation context
      next - what comes after this filter, called to continue and skipped to refuse
      Returns:
      the response