spring-cloud / spring-cloud/spring-cloud-gateway

Using templates to modify request/response bodies without needing Java DSL

Open
#3,138 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Is your feature request related to a problem? Please describe.

Evaluating using Spring Cloud Gateway as a replacement for a custom-built gateway that is currently on Spring MVC, one big pain point with the current feature set is having to use the Java DSL and writing custom code for mapping request/response bodies.

Describe the solution you'd like

To me it would be valuable to support request/response body templating similar to the body-transfomer in Apache APISIX which supports templates for mapping request and response bodies. This would allow for simple request/response mapping and would allow the current modifyRequestBody and modifyResponseBody behavior to be configuration-driven by YAML if desired (as opposed to only being code-driven right now).

Describe alternatives you've considered

Obviously the alternative is to do everything in code right now. There's certainly many templating languages that could be chosen from to support this, presumably it would be the same ones Spring currently supports (freemarker, thymeleaf, etc).

Additional context

Having dug around a bit, it looks like Spring supports reactive template rendering already, the only thing that would need to be extended is that the render function on View writes directly to the response object.

If we had something like a modifyRequestBodyFromTemplate we could resolve the template, provide a data model with the Spring context, and just provide a lambda to the current modifyRequestBody method that would render the template and return it. I think the hardest part would be getting the Spring View to render output to something other than the response like it does currently.

Is there any interest in this type of functionality? Not sure if it's a wide spread issue, or just my particular scenario being an aggregator/interface for internal APIs that exposes a more RESTful connectivity.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing modifyRequestBody and modifyResponseBody behavior and Spring's reactive template rendering, including AbstractView and its render function. Define how YAML-configured templates would supply a data model and produce request or response bodies without requiring Java DSL, then validate the design against the proposed modifyRequestBodyFromTemplate behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.