API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · Aula

GatewayFilters integrados que você deve conhecer

Explore as fábricas de GatewayFilter prontas para uso mais úteis, para resolver tarefas comuns sem escrever código personalizado.

Aula 4 de 413 etapas

GatewayFilters integrados que você deve conhecer é uma aula grátis de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Filters You Get for Free

Before writing custom filters, know that Spring Cloud Gateway ships with dozens of ready-made GatewayFilter factories. You attach them per route in configuration.

This lesson tours the ones you will reach for most often.

AddRequestHeader

AddRequestHeader injects a header into every request before it reaches the backend, useful for tagging traffic from the gateway.

filters:
  - AddRequestHeader=X-Source, gateway

AddResponseHeader

Likewise, AddResponseHeader adds a header to the response sent back to the client, for example a marker showing which gateway handled it.

filters:
  - AddResponseHeader=X-Handled-By, edge-gateway

RewritePath

RewritePath uses a regex to transform the incoming path before forwarding. Strip a public prefix while keeping the rest.

filters:
  - RewritePath=/api/(?<seg>.*), /$\{seg}

StripPrefix

When you just need to drop leading path segments, StripPrefix is simpler than a rewrite. StripPrefix=1 removes the first segment.

filters:
  - StripPrefix=1
# /service/users -> /users

PrefixPath

The reverse of stripping, PrefixPath prepends a segment to the path sent upstream.

filters:
  - PrefixPath=/internal
# /users -> /internal/users

SetStatus

SetStatus forces the HTTP status code of the response, handy for maintenance routes or deprecation notices.

filters:
  - SetStatus=410

RedirectTo

RedirectTo returns a redirect response with a status and target URL instead of proxying.

filters:
  - RedirectTo=302, https://new.example.com

RemoveRequestHeader

Strip a header before it reaches the backend with RemoveRequestHeader, for example to drop a client-supplied header you do not trust.

filters:
  - RemoveRequestHeader=Cookie

A Full Route Example

Filters stack in declared order. Here a route strips a prefix, tags the request, and marks the response.

routes:
  - id: users
    uri: http://users-svc:8080
    predicates:
      - Path=/api/users/**
    filters:
      - StripPrefix=2
      - AddRequestHeader=X-Source, gateway
      - AddResponseHeader=X-Handled-By, edge

Default Filters

Use default-filters to apply a filter to every route at once, such as adding a correlation header everywhere.

spring:
  cloud:
    gateway:
      default-filters:
        - AddResponseHeader=X-Gateway, true

Quick Check

You want to turn /api/users into /users by dropping the first path segment. Which filter is the simplest fit?

Recap

You now have a toolbox of built-in filters:

  • Header filters: Add/Remove request and response headers
  • Path filters: StripPrefix, PrefixPath, RewritePath
  • Response control: SetStatus, RedirectTo
  • default-filters apply globally

Reach for these before writing custom code, then build custom filters only when nothing fits.

Grátis para começar

Aprenda API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
12
Aulas
48

Perguntas Frequentes

A aula “GatewayFilters integrados que você deve conhecer” é grátis?

Sim — o texto completo de “GatewayFilters integrados que você deve conhecer” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), atualize para CoddyKit PRO. O curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) inclui 4 aulas no total.

O que vou aprender em “GatewayFilters integrados que você deve conhecer”?

Explore as fábricas de GatewayFilter prontas para uso mais úteis, para resolver tarefas comuns sem escrever código personalizado. Você pratica API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Nenhuma experiência prévia é necessária. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “GatewayFilters integrados que você deve conhecer”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Sim. Cada aula de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Filtros Globais e GatewayFilterFactory
  2. Filtros Personalizados de Requisição e Resposta
  3. Pré-processamento e Pós-processamento com Filtros
  4. GatewayFilters integrados que você deve conhecer
← Voltar para API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)