Skip to content

Also support optional HAL Link fields #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
edrik opened this issue Jul 20, 2013 · 12 comments
Closed

Also support optional HAL Link fields #100

edrik opened this issue Jul 20, 2013 · 12 comments
Assignees
Milestone

Comments

@edrik
Copy link

edrik commented Jul 20, 2013

The HAL support so far is great but for it to be really usable the optional link fields defined by the HAL specification should also be available.

There is a pull request #79 about adding a type and title but there are allot more optional fields defined by HAL. Not sure if adding all the fields to the Link class is the best solution but that would be a quick fix.

So far I've used a extended version of the Link class that adds the fields (and a fix for the issue with selecting the appropriate JsonSerializer, also noticed by #88). But that is far from ideal and makes allot of the convenience method unusable.

Any thoughts on how this could be implemented in a reasonably unobtrusive manner?

@fiddlerpianist
Copy link
Contributor

I'm frankly kind of surprised that Link isn't an interface (particularly since they are usually built with Builders rather than being instantiated directly). Also, why is the Atom namespace is coded directly onto the class? This makes it difficult and cumbersome to support HAL and in some cases actually deviates from Atom expectations. For instance, since href in HAL can be a URI template if the templated property is set to true, that means that the value in some cases is non RFC-5899 compliant.

I'm all for having Link be a link abstraction, but right now it seems like it's too close to Atom.

@drewcox
Copy link

drewcox commented Dec 9, 2013

I've done a lot of searching and this post seems to be the closest I've got to figuring out if I can build HAL template resource links with Spring HATEOAS. e.g "http://host/resource1/{id}/subResource". The answer appears to be "no". At best it tries to encode the "{", "}" chars, thinking I am trying to build a valid URL, not a templated one per http://tools.ietf.org/html/rfc6570.

@fiddlerpianist
Copy link
Contributor

drewcox: My fork adds a method to the Link class that renders the HAL template: true for URIs that have curly braces. I realize that doesn't cover everything, but it's a start to intuit whether a URI is a template. I've submitted a pull request for this addition.

@drewcox
Copy link

drewcox commented Dec 9, 2013

Hey, thanks for the quick response. Kind of new to GitHub, is it possible for me to access your fork? Thanks Drew

@fiddlerpianist
Copy link
Contributor

Yes. It's at https://github.com/fiddlerpianist/spring-hateoas. Look for recent commits from me.

@jiwhiz
Copy link

jiwhiz commented Apr 12, 2014

I'm trying to figure out how to build HAL links with "templated: true". If I use

BasicLinkBuilder.linkToCurrentMapping().slash("api/public/blogs/{blog}").withRel("blog");

The '{' and '}' chars are still encoded. Any idea how to build template URL links with Spring-hateoas 0.10.0.RELEASE by its API?

Thanks.

@rodriguezrps
Copy link

jiwhiz: you have a solution for the templated: true?

@jiwhiz
Copy link

jiwhiz commented May 6, 2014

@rodriguezrps yes, found some tricks.

I can use UriTemplate to build link directly with template, such as

String baseUri = BasicLinkBuilder.linkToCurrentMapping().toString();
Link blogsLink = new Link(
    new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_AUTHOR_BLOGS),
    AuthorAccountResource.LINK_NAME_BLOGS);

And use PagedResourcesAssembler to append pagination templates:

resource.add(assembler.appendPaginationParameterTemplates(blogsLink));

You can see examples at my blog https://www.jiwhiz.com/post/2014/4/Design_and_Build_RESTful_API_with_Spring_HATEOAS

@cperez1000
Copy link

@edrik : can you please post your solution? It'd be very helpful.

@edrik
Copy link
Author

edrik commented Sep 21, 2014

There is nothing special about the solution I'm using now. Its a extended version of the Link class that adds the attributes and can be construkted from an existing Link. Just need to do some extra wrapping in some places but its a reasonably workaround.

CustomLink halLink = CustomLink.of( plainLink ).setTitle("Foo")

@cperez1000
Copy link

@edrik
Thanks.. I had ended up doing the same thing, Just decorated Link to be able to still use the convenience methods.

gregturn added a commit that referenced this issue Mar 21, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 22, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 22, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Additionally, some of the files had inconsistent EOL characters. This patches that as well. To see the differences WITHOUT this bit, add ?w=1 to the github page showing the delta, and whitespace differences will be filtered out.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 22, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Additionally, some of the files had inconsistent EOL characters. This patches that as well. To see the differences WITHOUT this bit, add ?w=1 to the github page showing the delta, and whitespace differences will be filtered out.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 22, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Additionally, some of the files had inconsistent EOL characters. This patches that as well. To see the differences WITHOUT this bit, add ?w=1 to the github page showing the delta, and whitespace differences will be filtered out.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 22, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Additionally, some of the files had inconsistent EOL characters. This patches that as well. To see the differences WITHOUT this bit, add ?w=1 to the github page showing the delta, and whitespace differences will be filtered out.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 22, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Additionally, some of the files had inconsistent EOL characters. This patches that as well. To see the differences WITHOUT this bit, add ?w=1 to the github page showing the delta, and whitespace differences will be filtered out.

Resolves #100,#417,#235,#240,#238,#223
@gregturn gregturn self-assigned this Mar 26, 2017
gregturn added a commit that referenced this issue Mar 26, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Additionally, some of the files had inconsistent EOL characters. This patches that as well. To see the differences WITHOUT this bit, add ?w=1 to the github page showing the delta, and whitespace differences will be filtered out.

Resolves #100,#417,#235,#240,#238,#223
gregturn added a commit that referenced this issue Mar 26, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Related tickets: #100, #417, #235, #240, #238, #223
gregturn added a commit that referenced this issue Mar 26, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Related tickets: #100, #417, #235, #240, #238, #223
gregturn added a commit that referenced this issue Mar 26, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Related tickets: #100, #417, #235
Previous pull requests: #240, #238, #223
gregturn added a commit that referenced this issue Mar 26, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Related tickets: #100, #417, #235
Previous pull requests: #240, #238, #223, #79
gregturn added a commit that referenced this issue May 23, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Related tickets: #100, #417, #235
Previous pull requests: #240, #238, #223, #79
odrotbohm pushed a commit that referenced this issue Jul 28, 2017
Adds many additional attributes defined in RFC5988 and verifies they work properly in the neutral representation of Link while also being rendered properly in the HAL module.

Related tickets: #100, #417, #235
Previous pull requests: #240, #238, #223, #79
@odrotbohm odrotbohm added this to the 0.24 milestone Jul 28, 2017
@odrotbohm
Copy link
Member

Fixed with #567.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants