0

when I try calling this endpoint with just this endpoint: /api/v1/data/{provider}/{subject} (I removed @pathvariable dataset parameter when I got rid of the dataset path) I am able to successfully call my API. However, when I add an additional pathvariable (dataset in this case), I can't seem to hit my endpoint anymore. Is there some restriction on number of path variables? Not sure what I'm doing wrong.

@GetMapping("/api/v1/data/{provider}/{subject}/{dataset}")
public List<List<String>> getEDXDatasetHead(
            @PathVariable final String provider,
            @PathVariable final String subject,
            @PathVariable final String dataset,
            @RequestParam(required = false, value = "date") final String date
) 

https://localhost:8443/api/v1/data/testprovider/testsubject/testdataset @GetMapping("/api/v1/data/{provider}/{subject}/{dataset}")

3
  • Let me check if I understood this right. You have the endpoint configured as @GetMapping("/api/v1/data/{provider}/{subject}/{dataset}") and you call /api/v1/dataset/{provider}/{subject} and it does not work? Can you please be a little bit clearer? Commented Aug 10, 2021 at 15:41
  • Sure. The endpoint is @GetMapping("/api/v1/data/{provider}/{subject}/{dataset}") And I call: localhoststuff: api/v1/data/testprovider/testsubject/testdataset I can verify that my localhost port is correct because I can hit other endpoints. Commented Aug 10, 2021 at 15:48
  • Resolved. Due to a bug from dependency Commented Aug 10, 2021 at 18:36

1 Answer 1

1

There is no particular limit on number of PathVariable that you can add to a method.

But if you want to call your API with many different number of PathVariables you need to add a method for each of them, otherwise spring is not able to understand that you are calling the same method with a shorter number of path variables:

@GetMapping("/api/v1/data/{provider}/{subject}/{dataset}")
public List<List<String>> getEDXDatasetHead(
            @PathVariable final String provider,
            @PathVariable final String subject,
            @PathVariable final String dataset,
            @RequestParam(required = false, value = "date") final String date
) 


...


@GetMapping("/api/v1/data/{provider}/{subject}")
public List<List<String>> getEDXDatasetHead(
            @PathVariable final String provider,
            @PathVariable final String subject,
            @RequestParam(required = false, value = "date") final String date
) 

...


@GetMapping("/api/v1/data/{provider}")
public List<List<String>> getEDXDatasetHead(
            @PathVariable final String provider,
            @RequestParam(required = false, value = "date") final String date
) 

Note: spring doesn't have a particular limitation on the number of PathVariable that can be used in a method. But there are limitations on:

  • the size of the generated url (if too long not all browser handle it correctly)
  • the format of the url (check if you url encoded the path variables when you build the url on the client side)
Sign up to request clarification or add additional context in comments.

5 Comments

I agree with you on that, but I don't need to overload and only have one method with one endpoint (with all the required {} path formatting. I pretty much want that first method that you linked but when I try to hit that endpoint, it just fails.
post the url that fails and the the corresponding @GetMapping path
Sorry for delay, edited the urls into the question
@alexst your update seems correct, but differs from the original code. Are you using @GetMapping("/api/v1/**data**/{provider}/{subject}/{dataset}") or @GetMapping("/api/v1/**edx**/{provider}/{subject}/{dataset}") ?
I'm using "data". Was just trying something else in IDE but didn't change back. Apologies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.