Package dev.gmitch215.bytebox.http
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.
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 Summary
-
Method Details
-
filter
Response filter(Request request, Map<String, String> path, Env env, ExecutionCtx ctx, Supplier<Response> next) Sees the request.- Parameters:
request- the requestpath- what the matched pattern capturedenv- the bindingsctx- the invocation contextnext- what comes after this filter, called to continue and skipped to refuse- Returns:
- the response
-