Spring 云网关

Spring cloud Gateway

我有一个带有一些端点的 anexo API,例如:

 Localhsost:8080/api/clients  -> GET findall
 Localhsost:8080/api/clients/id -> GET findByID
 Localhsost:8080/api/clients -> POST insert a cliente
 Localhsost:8080/api/clients/id DELETE deleteByID

如何将 Spring 云网关与这些端点一起使用?

如果您不知道从哪里开始,您可以尝试遵循 属性-based 来自 dzone 文章 'Spring Cloud Gateway - Configuring a Simple Route'. You could configure just one of your services to begin with. That example suggests creating a spring cloud gateway project from the spring initializr 的示例,方法是选择 'gateway' 依赖项并添加路由到 application.yaml:

spring:
  cloud:
    gateway:
      routes: 
        - predicates:
            - Path=/props/**
          filters:
            - StripPrefix=1
          uri: "http://httpbin.org"

因此您可以将 httpbin.org 替换为 localhost:8080,并将 /props/** 替换为您的路径 - /api/clients/**。您可以通过调用 http get 来测试它,然后尝试添加第二个服务。在您的情况下,我怀疑您想删除过滤器以去除前缀,因为听起来您的服务正在公开一个 /api/clients 端点,因此您可能希望保留整个路径。那是 you'd need to check.