Spring Cloud Gateway

This project provides a library for building an API Gateway on top of Spring MVC. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.)..

Quick Start
Fork me on GitHub

Features

Spring Cloud Gateway features:

  • Built on Spring Framework 5, Project Reactor and Spring Boot 2.0
  • Able to match routes on any request attribute.
  • Predicates and filters are specific to routes.
  • Hystrix Circuit Breaker integration.
  • Spring Cloud DiscoveryClient integration
  • Easy to write Predicates and Filters
  • Request Rate Limiting
  • Path Rewriting

Quick Start

Download

The recommended way to get started using spring-cloud-gateway in your project is with a dependency management system – the snippet below can be copied and pasted into your build. Need help? See our getting started guides on building with Maven and Gradle.

@Configuration
@SpringBootApplication
public class Application {

  @Bean
  public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) {
    return Routes.locator()
      .route("test")
          .uri("http://httpbin.org:80")
          .predicate(host("**.abc.org").and(path("/image/png")))
          .addResponseHeader("X-TestHeader", "foobar")
          .and()
      .route("test2")
          .uri("http://httpbin.org:80")
          .predicate(path("/image/webp"))
          .add(addResponseHeader("X-AnotherHeader", "baz"))
          .and()
      .build();
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}

To run your own gateway use the spring-cloud-starter-gateway dependency.

Sample Projects