Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: A straightforward method to use environment variables to configure API's URI #269

Closed
ejba opened this issue May 2, 2020 · 2 comments

Comments

@ejba
Copy link

ejba commented May 2, 2020

Usually, I configure API addresses through environment variables. I wished there was a straightforward method to configure those addresses on the interfaces.

E.g.

@RegisterRestClient(envVar="API_URI")
@Path("/api")
interface ExampleApi {
    @GET
    @Path("/example/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Example getExample(@PathParam("id") Integer id)
}
@andymc12
Copy link
Contributor

andymc12 commented May 4, 2020

Hi @ejba - you should be able to set the base URIs using environment variables. For individual client interface, for example:

package my.pkg;

@RegisterRestClient
@Path("/api")
interface ExampleApi {
    @GET
    @Path("/example/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Example getExample(@PathParam("id") Integer id)
}

You would use the MP Config setting of my.pkg.ExampleApi/mp-rest/uri=http://somehost:9080/someContextRoot. MP Config allows you to use the environment variable of MY_PKG_EXAMPLE_API_MP_REST_URI.

If you want to configure multiple interfaces with the same base URI, you could use config keys - for example:

package my.pkg;

@RegisterRestClient(configKey="rest_client_api")
@Path("/api")
interface ExampleApi {
    @GET
    @Path("/example/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Example getExample(@PathParam("id") Integer id)
}
package some.other.pkg;

@RegisterRestClient(configKey="rest_client_api")
@Path("/api2")
interface ExampleApi2 {
    @GET
    @Path("/example2/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Example2 getExample2(@PathParam("id") Integer id)
}

then you could use the environment variable, REST_CLIENT_API_MP_REST_URI to set the base URI for both clients.

@ejba
Copy link
Author

ejba commented May 4, 2020

I didn't know that combo! Thanks for the explanation!

@ejba ejba closed this as completed May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants