Hi kindof new to this whole HATEOS thing, but I have gotten some suff working. I'm having a very weird issue related to CurieProvider
I have added the CurieProvider in to my application and it works quite well the weird part is now I'm getting two _links In my API here is an example response
{
"_embedded": {
"bp:channelList": [
{
"name": "general",
"subscription": "/channel/general",
"_links": {
"self": {
"href": "https://api.turkuforge.fi/channel/general"
}
}
},
{
"name": "random",
"subscription": "/channel/random",
"_links": {
"self": {
"href": "https://api.turkuforge.fi/channel/random"
}
}
}
]
},
"_links": {
"curies": [
{
"href": "https://docs.turkuforge.fi/{#rel}",
"name": "bp",
"templated": true
}
]
},
"_links": {
"bp:sockjs-endpoint": {
"href": "https://api.turkuforge.fi/connect"
},
"self": {
"href": "https://api.turkuforge.fi"
},
"curies": [
{
"href": "https://docs.turkuforge.fi/{#rel}",
"name": "bp",
"templated": true
}
]
}
}
live API can be found here and all the code can be found here https://github.com/TurkuForge/baby-project-server
I have been digging in to the issue and it seems that when I do this (can be found on line 43 in RootApiController)
val model = HalModelBuilder.halModel()
getChannels().forEach {
val link = linkTo<ChannelController> { message(it, null) }
val channel = Channel(it, link.toUriComponentsBuilder().build().path)
channel.add(link.withSelfRel())
model.embed(channel)
}
it also adds the second link. I'm not sure why this happens, but its very easaly reproducable since it happens no matter what I do
The API you link to actually shows this document:
{
"_embedded": {
"bp:channelList": [
{
"name": "general",
"subscription": "/channel/general",
"_links": {
"self": {
"href": "https://api.turkuforge.fi/channel/general"
}
}
},
{
"name": "random",
"subscription": "/channel/random",
"_links": {
"self": {
"href": "https://api.turkuforge.fi/channel/random"
}
}
}
]
},
"_links": {
"bp:sockjs-endpoint": {
"href": "https://api.turkuforge.fi/connect"
},
"self": {
"href": "https://api.turkuforge.fi"
},
"curies": [
{
"href": "https://docs.turkuforge.fi/{#rel}",
"name": "bp",
"templated": true
}
]
}
}
which looks correct to me?
@odrotbohm I think you might be looking at something that is parsing the JSON. While developing the API I was looking at it in chrome with a JSON beautifying addon. That's why I didn't catch it before I deployed the API. But one of our engineers who was developing iOS said he is getting two links in the response and then I realized the problem was when adding the embedded.
I am aware I do it a bit weirdly with adding the links after I already run build on the mode but tested locally and adding the links using the model.link method produces the same results.
I've tried to actually debug the project for an hour now, but have to give up. Would you mind preparing something that's plain Java (so that I am not forced into IDEA) and ideally does not use Gradle? I've tried to run the test case, but IDEA tells me that the used Gradle version cannot run on JDK 16. Please be as simple as possible: Java 8/11, Maven, a failing test. That'd be incredibly helpful, thanks!
Nevermind, I think I got to the root cause. Working on it.
This should be fixed in the latest snapshots. Also backported to 1.3.x (#1570) and 1.2.x (#1571).
@odrotbohm Awesome that you got it fixed I was looking in to it my self and had a plan for how to fix it but you beat me to it and your solution is better then what I had in mind 👍🏼 And in the future I will remeber to simplify my examples. I am more use to gradle than maven so I always just use gradle. Also the project was still on java 15 so thats why 16 could not build. I will update it to 16 ASAP. Thanks again for the help!
Lovely, no worries. Gradle is generally fine, but the version used should work with the latest available Java version then. We generally work with those plus the LTS versions. Kotlin is slightly more problematic, as it restricts me to use IDEA, which – at least for me – reduces my productivity by a large margin. 😬
Anyway, hope you see this working now. Releases coming mid July.