-
Notifications
You must be signed in to change notification settings - Fork 473
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
Add Traverson support to the usual HTTP method verbs (POST, PUT, DELETE and PATCH) #225
Comments
I would also be very interested in this enhancement. |
+1.. Anyone? |
It looks quite simple, and would certainly be nice to have, for example the following could be added to TraversalBuilder:
Where an additional prepareRequest overload is added to allow request with body to be created. |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
I'd love to learn more about the actual use-cases to include non-safe and non-idempotent HTTP methods in the traversal. The reason I am curious about this that I so far considered a traversal something that's a discovery of resources to eventually end up at one that a more advanced business operation is invoked on. That sort of implies repeatability of the traversal which breaks apart if the traversal contains non-safe or non-idempotent HTTP requests. For example, see how this traversal basically looks up a resource and the client the uses the eventually discovered link to expand that and let the actual client do whatever it wants with it. That way the discovery is separated from the final invocation and can be refreshed automatically, e.g. in case the resource becomes outdated and needs to be rediscovered, something the Spring Cloud integration does for you automatically. |
Oh, and in case you missed it, GitHub has a voting feature that can be used on the original comment to indicate support. No need to add more "+1" comments :). |
|
And that's quite analogous to reactor flows. I wonder if this is something better served when we add reactor support. |
Hm, I see. Traverson is currently not built to be a generic HTTP client or the central API to build an interaction with a REST API around, but one to discover resources by following links (as the both the JavaDoc and the API clearly express). It currently also lacks the ability of dynamically inspecting responses and reacting on the presence or non-presence of links, which also should make this very obvious. This in turn means that the rather technical request to add support for other HTTP methods sort of contradicts the current design constraints and is basically asking the wrong question :). Also, I've never understood "following a link" — which is the only thing exposed in the API currently — to be anything else than a GET, mostly because also in HTML there's a clear distinction between following (clicking) links on an anchor and issuing commands through forms. I am not sure that blending these two things is a good idea. I actually like the fact that Traverson does one thing and serves that one thing well. The whole point about Traverson is that it doesn't need any more knowledge about the server than link relations, URI templates and how to expand them as well as hypermedia types. All the things you describe already use API specifics (i.e. what exactly to post to a URI) and embrace a lot more dynamics. Think of it as the guide that finds a product at Amazon, but then let's you figure out what to do with it. If you want much more control over all this, I wonder what the benefit of a wrapping Traverson actually is compared to a |
I thought this was supposed to be a port of the original Traverson, which provides such features. If they're not going to be added, then the number of use cases that can be addressed with this project are so small that I don't see the point, really. |
In my case I has an integration system, which receives message from outside and store it in another system with REST API. The class is mixed, if it possible I prefer one code style. As for me Traverson is simpler because we can use chained methods to build it and run requests lazely, as it performs only in toObject and toEntity methods.
Yes, I agree it can be better. Ideally for us and I think it will be usefull for other users who use Spring Data REST, is to have client in the same way as server out of the Spring box. I know there are some community implementations, but it will be more serious to have one from Spring. :) I mean something like:
Then resolve HTTP methods by default with names. Or with overrides and Annotations: @put, @get, ... I see that it's can be not the best solution, for example, because of @query, which we don't need on client side. But it's save time and maybe to think in this direction. |
Interesting conversation. In my case I wanted the other verbs so that I could perform a number of GET requests / traversal steps but then make a (potentially) non idempotent operation at the end of the chain. @olivergierke you'll see I've hacked (admittedly not very well) your code here to do what I wanted in terms of PUT, POST and DELETE using Traverson. The actual modified Traverson package is here. You can see the real life use case in README.md or you can just run the console app. Stuff I care about:
Maybe I'm asking too much or my use case is too specific :) |
Idempotence as a design goal in this case seems a bit unexpected. While graph traversal IS based on a set of non-modifying operations, the idea of some sequences of steps needing to always be repeatable seems unlikely, especially since for practical purposes most systems expose multiple ways to modify the backing data independently and thus the traversal would change as well. I see there are cases for this "locked down" approach, but maybe both it and a more robust set of methods can be supported by configuring which features one wishes to expose or consume. Since the server can choose the former, it makes sense of clients (like Traverson) to allow choice in the latter - being able to configure a non-modifying client. I think the main point is: RestTemplate is still a bit klunky, and for Hateoas APIs Traverson is superior, so why not extend it and actually turn it into a more full-fledged tool? |
I was hoping to use Traverson w/ MockMVC to simplify some testing, but with only GET support, I don't see how Spring's Traverson is of much use at all. It feels somewhat misleading to call this "Traverson" at all. Inspired by it? Sure, minimally in its API design. But this is not at all the Java version of Traverson and it just becomes confusing by calling it such. |
Similar to what the actual javascript client support: https://github.com/basti1302/traverson#post-put-delete-and-patch
The text was updated successfully, but these errors were encountered: