3 ms·
"< [XML packet full of endpoints comes back]" I'm going back and forth on this one. On the one hand, it is a pain to go through those steps if you already kno
by jimbokun 17y ago
"< [XML packet full of endpoints comes back]"
I'm going back and forth on this one. On the one hand, it is a pain to go through those steps if you already know which service you want. On the other hand, having that listing available makes the site kind of self documenting, in that you can explore the services available.
What I find more potentially useful is the idea of putting URLs into the XML for subordinate resources instead of some kind of ids or other identifiers. Then the client can follow those URLs to get a user's documents, or whatever it is you are modeling. Anything where there is a relationship but it is too expensive to just dump all the data in a single XML response.
It's pretty intuitive, and arguably easier than just supplying an id that the client must use to construct the appropriate URL.
- psadauskas 17y agoOnce you write a client, and its pretty simple, you don't have to worry about that step at all. And since the initial document rarely changes, and it can be cached, you usually only have to get it once. Here's some code in ruby that uses a service like this to find a user by their login: def find_user(login) users.select { |u| u["login"] == login }.first end def users users_href = services.select { |s| s["name"] == "AllUsers" }.first["resource_href"] JSON.parse( @http.resource(users_href).get(:accept => SSJ).body )["items"] end def services JSON.parse( @http.resource(@services_uri).get(:accept => SSJ).body )["items"] end @http is a handle to an HTTP library, and @services_uri is the well-known URI. So its not nearly as complicated as it might seem at first, and the benefits are tremendous.