0

I'm facing the following issue and have been able to find a proper fix.

As a use case example, let's imagine a Rest client that fetches a json object from a server, where the request is the path to the object. This api does not accept query parameters nor bodies, and no catalogue is available.

say that I have the following RestClient:

@Path("/json")
@RegisterRestClient(configKey="json-api")
public interface JsonService {

    @GET
    @Path("/{MyVariableLengthEndpoint}")
    Response getJson(@PathParam("MyVariableLengthEndpoint") ????? endpoint);
}

Examples of requests could be :

  • /json/employees/Dwight/jobs/assistantRegionalManager/salary
  • /json/games/theLastOfUs/rating

Passing a string with / characters gets encoded with %. To bypass this, I've tried:

  • Using the @Encoded annotation
  • Adding a regex in the pathParameter {MyVariableLengthEndpoint: .*}
  • Passing a List<PathSegment>

None of those worked.

Is there a proper way to do this ?

Grizzlyman
  • 53
  • 6
  • I have never used it, but `@ClientURI` may be the solution (https://docs.jboss.org/resteasy/docs/3.8.1.Final/userguide/html_single/index.html#ClientURI). Let me know! – Luca Basso Ricci Jan 27 '23 at 11:17

1 Answers1

0

You should use Regex in your @Path definition, something like this:

@GET
@Path(“/{varPath : .+}”)
Response getJson(@PathParam(“varPath”) String endpoint);

This will match anything that comes after /json.

For more info search: “JAXRS path Regex”, on Google.

Serkan
  • 639
  • 5
  • 14