Middleware Insertions
Aperture supports inserting middleware into the request pipeline, which makes it easy to integrate with less code changes.
What is a Middleware Insertion?
It is a way to add a new layer of functionality to the request pipeline. It is a piece of code that can be executed before or after the request is processed by the application. Allowing you to add new functionality to the request pipeline without changing the application code.
How to add a Middleware?
There are multiple ways to add a middleware, and it depends on the language and framework you are using. For example, in Spring Boot, you can register a Spring Boot Filter, in Armeria you can register a decorator, in Netty, you can register an Aperture Handler. Let's examine how to add a middleware insertion in Spring Boot.
How to add a Middleware in Spring Boot?
In Spring Boot, you can register an Aperture filter, which automatically sets the feature control points. Here is an example:
import com.fluxninja.aperture.servlet.jakarta.ApertureFilter;
...
@RestController
public class AppController {
...
@RequestMapping(value = "/super", method = RequestMethod.GET)
public String hello() {
return "Hello World";
}
...
@Bean
public FilterRegistrationBean<ApertureFilter> apertureFilter(Environment env){
FilterRegistrationBean<ApertureFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new ApertureFilter());
registrationBean.addUrlPatterns("/super");
registrationBean.addInitParameter("agent_host", "localhost");
registrationBean.addInitParameter("agent_port", "8089");
return registrationBean;
}
}
Aperture provides different middlewares for different java frameworks, which you can check out in the Java section. There are examples available for each framework.
What's next?
Once the middleware insertion is done, head over to install Aperture.