I want to develop an application that acts as client for "RESTlike"
services like Flickr. At the moment I'm using the jersey client library.
Flickr, for example, provides XML and JSON representations.
What are the prefered ways to implement a REST client with Play!? How
to parse the XML or JSON responses of the REST sevices?
I can only find information about how to act as RESTful service and
how to provide XML or JSON representations but not how to consume them.
Thanks,
Tristan
AFAIK Play only provides tools to make a server, so for the client
part I think you're fine using the Jersey library or any library you
like.
You can also use service-specific libraries such as flickrj or jickr
for Flickr for example.
--
Erwan Loisant
the Jersey client library is what I'm currently using and it feels
really straightforward.
The service-specific are no alternatives for me, because I have to
integrate at least 10 services. So I want a generic interface.
My problem is now how to handle the XML and JSON stuff I'm getting as
response from the services. Possible ways are DOM, JDOM, SAX, StAX,
JAXP, JAXB. I can't find a way out of this tangle.
Clientside "posting" (as Karim mentioned) is not possible for me because
my app offers a RESTful service, where in most cases no browsers are
involved.
Erwan Loisant schrieb:
On Mon, Nov 9, 2009 at 10:26, Tristan Wehrmaker <3S...@3stan.net> wrote:
> the Jersey client library is what I'm currently using and it feels
> really straightforward.
>
> The service-specific are no alternatives for me, because I have to
> integrate at least 10 services. So I want a generic interface.
I see.
> My problem is now how to handle the XML and JSON stuff I'm getting as
> response from the services. Possible ways are DOM, JDOM, SAX, StAX,
> JAXP, JAXB. I can't find a way out of this tangle.
> Clientside "posting" (as Karim mentioned) is not possible for me because
> my app offers a RESTful service, where in most cases no browsers are
> involved.
It's mostly a matter of preference. As far as I'm concerned, I prefer
to work with JSON for various reasons so I do so when I can. Then of
course some services will only provide you responses in XML. In this
case:
* SAX and its friends are event-based, so you can work on an XML
Stream while DOM requires you to have to whole document before working
on it.
* DOM and JDOM do a full parsing, so it's easier to work with.
In your case I don't think SAX is worth the pain, since you'll have to
parse the whole document before generating the template anyway. So I
think you should use DOM or JDOM. DOM is based on the W3C standard, so
if you're used to it already (because you used it in Javascript) maybe
it's better for you. JDOM is designed to be a simpler API so if you're
not used to DOM already it could be better for you.
Look at the code samples, see which one you prefer!
--
Erwan Loisant