spring-projects / spring-projects/spring-hateoas

Allow disabling URL encoding in traverson

Open
#1,707 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

We have a REST API that allows repeating parameters and this issue is thus related to another issue I just posted, https://github.com/spring-projects/spring-hateoas/issues/1706. Again, I'm not sure how or even if repeating parameters are supported by the HAL specification, but this is how the service returns the link that supports repeating (accountId) parameters:

{
  "_links": {
    "stuff": {
      "href": "https://someurl.com/api/stuff{?accountId,page,size,sort}",
      "templated": true
    },
    ....
}

I.e. you can make the following request:

https://someurl.com/api/stuff?accountId=1234&accountId=5678

Since it doesn't work to use a list for "accountId" in the withTemplateParameters method (see https://github.com/spring-projects/spring-hateoas/issues/1706), i.e. I can't do something like this:

Map<String, Object> parameters = new HashMap<>();
parameters.put("page", page);
parameters.put("size", size);
parameters.put("accountId", List.of("1234", "5678"));

return traverson.
        .follow(rel("stuff"))
        .withTemplateParameters(parameters)
        .toObject(..);

we've previously used the following ugly workaround:

Map<String, Object> parameters = new HashMap<>();
parameters.put("page", page);
parameters.put("size", size);
parameters.put("accountId", List.of("1234", "5678").stream().collect(Collectors.joining("&accountId=")));

This used to work when using an old version of spring hateoas (in our case 0.25.1.RELEASE). The reason why it worked was that Traverson didn't URL encode the parameters. But after upgrading to 1.3.6, it seems like URL encoding happens automatically and this hack no longer works.

While I acknowledge that this is not the best use case for allowing one to disable URL encoding, I still think that such an option would make sense.

WDYT?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Traverson's withTemplateParameters handling and the URL-encoding step; the issue provides no file or test names. Review the related issue #1706 and existing Traverson tests, then define coverage for repeated accountId parameters and the requested encoding option before considering the work complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.