ecamp / ecamp/ecamp3

Resource IRIs have changed after moving API to subpath

Open
#3,308 3 comments 0 reactions 0 assignees View on GitHub
agents:ignore
Dominant language
PHP
Stars
156
Forks
72
Avg merge
12h 43m
Merged PRs (30d)
203

Description

After #3222 and #3262, the IRIs of our hal resources have changed (prefixed by `/api`).

For storing in vuex and handling in hal-json-vuex, the `/api` prefix is stripped (this is handled by `hal-json-normalizer`). Currently, there's a [bug in hal-json-normalizer](https://github.com/carlobeltrame/hal-json-normalizer/pull/87) that leads to problems for printing. Independent of that, there could be potential problems down the road. As an example, we also use IRIs in query parameters and they are not normalized by hal-json-normalizer (and probably will never be). Any manual handling of these query parameters could lead to inconsistencies between hal-IRIs and vuex-IRIs:

### API response
```javascript
{
"_links": {
"self": {
"href": "/api/camps/c4cca3a51342"
},
"campCollaborations": {
"href": "/api/camp_collaborations?camp=%2Fapi%2Fcamps%2Fc4cca3a51342"
},
},
"id": "c4cca3a51342"
}
```

### Vuex store
(notice the `%2Fapi` in the `campCollaborations` link)
```
{
"id": "c4cca3a51342",
"campCollaborations": {
"href": "/camp_collaborations?camp=%2Fapi%2Fcamps%2Fc4cca3a51342"
},
"_meta": {
"self": "/camps/c4cca3a51342",
}
}
```

### Options
Hence I'd like to have a discussion on the best way forward and take a conscious decision. Potential options I see:

**A. Adjust API to return IRIs without `/api`**
I couldn't find any way to configure this. Plus it may contradict the HAL logic that links can just be followed by humans.
We could open an issue on API-platform though to verify, if someone else has a solution or if API-platform would accept a PR for this.

**B. Don't strip `/api` in vuex store**
Consistency between API response and Vuex store. Needs some adjustments in our codebase though (baseUrl for axios would change to http://localhost:3000/ which has some implications).

**C. Leave as-is**
Probably no further change needed after fixing the hal-json-normalizer bug. For future, be careful to not run into inconsistencies (e.g. manual handling of query parameters).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.