Dependencies
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
application.properties (optional)
If you set false, the gateway will be disabled
spring.cloud.gateway.enabled=true
MainApplication.java
@SpringBootApplication
public class Demo10Application {
public static void main(String[] args) {
SpringApplication.run(Demo10Application.class, args);
}
@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(p -> p
.path("/get")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri("http://httpbin.org:80"))
.build();
}
}
Test
When we call this API
curl http://localhost:8080/get
It will give us the response generated from http://httpbin.org:80/get
with the extra field in the header Hello World