-
Notifications
You must be signed in to change notification settings - Fork 18
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
Ability to use links as the source for 'options' #74
Comments
can you expand on this a bit? possibly write up a short example that includes the HTTP request/response that you want to support? |
Yes, given a field:
A client might do the following request: GET /category HTTP/1.1 Which results in the following response: HTTP/1.1 200 OK
Content-Type: application/hal+json
{
"_links": {
"self": { "href": "/category" },
"item": [
{ "href": "/category/1", "title": "Gardening"},
{ "href": "/category/2", "title": "Cooking"},
]
} This might ultimately render: <select name="category">
<option value="/category/1">Gardening</option>
<option value="/category/2">Cooking</option>
</select> Important though is that the use of HAL is not prescribed, if our response to HTTP/1.1 200 OK
Content-Length: 0
Link: </category/1>; rel=item title=Gardening
Link: </category/2>; rel=item title=Cooking Does that make sense? |
To expand on that, if our list of HAL categories returns something like this instead: HTTP/1.1 200 OK
Content-Type: application/hal+json
{
"_links": {
"self": { "href": "/category" },
"item": [
{ "href": "/category/1", "title": "Gardening"},
{ "href": "/category/2", "title": "Cooking"},
],
},
"_embedded": {
"item": [
{
"_links": {
"self": { "href": "/category/1"},
},
"title": "Gardening",
"color": "green"
},
{
"_links": {
"self": { "href": "/category/2"},
},
"title": "Cooking",
"color": "red"
}
]
}
} A client could choose to use the 'color' to further enhance the UI. Important note though, that should not be prescribed in HAL-Forms. HAL Forms should just talk about the fact that the list of options is a list of links, and not say anything about how they might be rendered; that's up to the application. HAL Forms just requires that the target resource uses something that uses Weblinks and leave it up to the application to try and interpret that, send the right Accept headers, etc. |
OK, i think i am getting it. the current spec lays out "link" interactions for if i have it about right -- that means we need to come up w/ the rules for other media types, too. for starters, i'd like to see worked up versions of |
I would want to suggest to completely leave out media-type specific information. All of these formats and HTML all use the same semantic concept of a web link. It's up to the client to figure out (and negotiate) what they can support. A comparison is the HTML This is not unlike regular links in HAL, HAL doesn't require your links to point to other HAL documents. The client is in charge of navigating the web and knows what it can and cannot interpret. If a client only understands HAL for this purpose, they would include The only requirement in HAL Forms is that the target URI should return something that's conceptually a RFC8288 Web Link. |
Another comparison I have is the https://tools.ietf.org/html/draft-pot-prefer-push-01 This spec was supposed to inform servers what resources to push via HTTP/2, but the client specified these resources via their link relationship ( |
OK. color me a skeptic but that might be due to my not "getting it" quite yet. here's what i suggest. show us a working version of what you'd like to see. essentially, extend HAL-FORMS locally to do what you want and show a client working as you wish. let's see where that leads us. |
I will! |
thanks. looking forward to it. ping me directly if you need anything at all. |
I completely agree we need something like this. The biggest problem I see currently is the Requesting the categories with [{
"title": "Gardening", "color": "green"
},{
"title": "Cooking", "color": "red"
}] Requesting the same categories with {
"_links": {
"self": { "href": "/category" },
"item": [
{ "href": "/category/1", "title": "Gardening"},
{ "href": "/category/2", "title": "Cooking"},
],
},
"_embedded": {
"item": [
{
"_links": {
"self": { "href": "/category/1"},
},
"title": "Gardening",
"color": "green"
},
{
"_links": {
"self": { "href": "/category/2"},
},
"title": "Cooking",
"color": "red"
}
]
}
} Now, what is the correct, common value of I think we either need to leave out the |
I have 2 notes here that might help with this:
I agree with the general premise of though that not every content-type will have a concept of a weblink, but perhaps adding a |
Isn't that actually just stating that the client has to understand the media type returned by the server and the media types' way of expressing collections? 🤔 If that media type doesn't have a very precise way of describing that, then it might not be a good candidate to return remote options, unless you're willing to live with some wiggle room for client implementations. That said, I think HAL in particular is well enough defined to support that case (see my comment on the other ticket). I think a smart client could pick up all elements of the I think we're very well set up by the spec defining a prompt and a value and primarily rely on API authors to find ways to prepare responses in a way that they're easily processable for a HAL FORMS client without disambiguation. I don't think we should go ahead and try to make every existing resource representation – even if it's HAL based – that someone made up, work. |
What strikes me as odd about the requested semantics for |
Following your wording, and how I consider the HAL spec wants this, I think the appropriate way to find all 'collection items' is not to look in There is nothing else in the HAL drafts that suggest that the inclusion of anything in |
Using |
For a while we actually had a system that would do HTTP/2 Pushes instead of HAL embeds for connections that supported it because to me they have the same purpose. =) |
I am not sure, why you think we're "overloading" anything here. The most exhaustive example clearly shows entries in If the document contains multiple entries we have two options (haha!). Either teach HAL FORMS which of the keys to use (which I'd like to avoid because it comes with a lot of HAL specific implicit knowledge and: do we want to do this for other media types as well?), or the client can fall back to pick up all keys' values (because it doesn't care about rels and grouping elements by rels), which might lead to not perfect results because there's no guarantee about ordering, duplicates etc. but is a decent fallback. If you want to avoid the problems of multiple key, again, you can expose a dedicated resource to arrange the results in a less ambiguous structure. I think it's a pretty cool example how tow media types can nicely link together without actually baking too much knowledge about one into the other.
Well, the HAL FORMS' |
I agree that a dedicated resource with just one rel in But when that is not a possibility for a given API server, collecting objects from multiple embedded arrays with different rels makes no sense to me - objects in different rels might not even have the same data structure and fields. Consider the following response: {
"title": "Moby Dick",
"_links": { "self": { "href": "/books/1" }, "author": { "href": "/authors/1" } },
"_embedded": {
"chapters": [
{ ... }, { ... }
]
}
} Assume I use this resource for the options of a dropdown select field that allows to choose one chapter of the given book. Some time later, another developer decides that a book might be written by multiple authors, and changes the response on this endpoint to this: {
"title": "Moby Dick",
"_links": { "self": { "href": "/books/1" }, "authors": { "href": "/authors?book=1" } },
"_embedded": {
"chapters": [
{ ... }, { ... }
],
"authors": [
{ ... }, { ... }
]
}
} Suddenly, because of a completely unrelated change, my chapter selection starts bugging out (in case the id and name fields are not called the same for chapters and authors), or even worse, starts offering authors for selection. As stated above, using the entries returned from |
@odrotbohm Although I think you are wrong, it's not my goal here to convince you of this ;) We're talking a bit in circles now, but the reality is your usage of HAL / Another nice benefit of targeting web links by Another thing that desperately needs to be discussed is: what are the values that would be sent? In my proposal in this issue, the value would end up being the How did you and @toedter envision the |
@carlobeltrame – Aren't we discussing a straw man here? How likely is it that the resource objects contained in these collections, that are obviously designed for completely different purposes contain @evert - I am not "adding more semantic meaning". I am citing the spec. 🙃 The representations looked like this: {
"_embedded" : {
"doesn't-really-matter" : [
{ "value" : "…", "prompt" : "…" },
{ "value" : "…", "prompt" : "…" }
]
}
} That seemed to be in line with "we remove the HAL-induced envelope" and then apply the semantics required by HAL FORMS. I guess we need to decide whether the focus of this ticket is on |
This example makes sense, if you want to allow embedding arbitrary data that are not HAL resources (don't have a URI). I don't see a reasonable way to support this; but if this makes it in the spec we simply won't implement it. There's at least some support that this is weird from the spec author (editorialized):
An alternative for you might just be to define a media-type that explicitly means: "This is a HAL-flavored response, that uses a specific format in |
We use HAL because we like using links. Aside from the 'discovery' benefit, we heavily use links to express relationships between entities. For example, a blog
article
might have manycategory
links.The majority of the cases where we will be using the new
options
feature is to let users specify these relationships (let a user select a category when writing an article).The ability to use a link to specify the source for the dropdown is helpful but has some drawbacks. We would like to be able to select the 'source' for a property by specifying:
rel
.For example, in the article category case we'd want to point to a 'categories' collection and the 'item' rel.
What does this give us:
I feel that this is a very natural fit for HAL Forms and HATEOAS in general.
The text was updated successfully, but these errors were encountered: