Pass base url or host as a param
See original GitHub issueI have a use case where I have a list of hosts, I need to loop over those hosts and make the same api call for each of them. I don’t want a hardcoded base url as that would mean creating a new feign client for each api call.
I would like to do something like:
public class FeignBaseUrlParamTest {
@Test
public void testIt() {
MyClient client = Feign.builder().target(Target.EmptyTarget.create(MyClient.class));
client.internalService("http://localhost:8080");
}
}
interface MyClient {
@RequestLine("GET {baseUrl}/internal-service")
String internalService(@Param("baseUrl") String host);
}
However this encodes the base url part and the following exception occurs:
feign.RetryableException: no protocol: http%3A//localhost%3A8080/internal-service executing GET http%3A//localhost%3A8080/internal-service
I tried to create a Target implementation which gets the url out and decodes everything before the path. However it is not possible as you can only perform additions to the url from that context.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How to set base url and query parameters for WebClient?
Is it possible to set scheme, host, port in a method together? I know that webClient.get().uri("http://a.com:8080/path1?param1=v1").retrieve() ...
Read more >Base URL - Testim overview
Base URL · Running remotely · Base URL Parameter · Overriding base URL and navigation hosts · Rerun with the same parameters.
Read more >API Host and Base Path - Swagger
REST APIs have a base URL to which the endpoint paths are appended. The base URL is defined by schemes , host and...
Read more >Adding Base URL to REST Service
A base URL path includes the hostname of the server where the REST Service ... parameter is an expression that represents a value...
Read more >What is the composition of the URL? in REST API - Numpy Ninja
The base URL is the internet host name for the REST API. The resource path is the address to the API resource. Query...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think you want to just add an unannotated URI param
interface MyClient { @RequestLine(“GET /internal-service”) String internalService(URI baseUrl); }
That works perfectly. Thanks