I would like to use Spring Data REST with HATEOAS links behind an API Gateway. My native API in Spring Data REST is configured with spring.data.rest.basePath=/nativeapi, so the resources will be available at, e.g., http://localhost:8090/nativeapi/people.
In my API Gateway, I would like to redirect requests for /proxyapi to /nativeapi on the native API. For example, requests for http://localhost:8080/proxyapi/people will be redirected to http://localhost:8090/nativeapi/people.
Now I would like to have the HATEOAS links in the response be correctly pointing at the API Gateway URL with the right prefix. How can I do that in Spring Data REST?
I know that I can add a ForwardedHeaderFilter which will inspect the x-forwarded headers, but, as far as I know, this will only let me change the protocol, the hostname, the port, and add a prefix. But I have to replace the prefix /nativeapi in the HATEOAS links by /proxyapi (in addition to changing the hostname, port, and maybe also the protocol). How can I do that? Thanks!
Just an idea: The API Gateway could send a custom HTTP request header like x-forwarded-replace-prefix=/nativeapi that will tell the Spring Data REST application to replace the /nativeapi prefix in its HATEOAS links by the prefix it gets in the x-forwarded-prefix=/proxyapi header. Would that be possible?