简体   繁体   中英

Passing json data between client and server

I need to implement web services, send json to a server and read the response. All of the requests are send to the service https://api.polldaddy.com/ This will take place within a web application. This is the api I have to implement :

http://support.polldaddy.com/api/

It seems straightforward, just send some json to the server and consume the json response that is sent back. There seems to be so many options of doing this task that its a little daunting where to start ?

So, where is the best place to start in learning how to implement this service, ie : send json to a server and consume the response.

If there is no JAVA API already written I would go for a JAX-RS approach with a client framework like jersey client. Look at http://jersey.java.net/nonav/documentation/latest/client-api.html .

First of all, you are using the wrong terminology. "Implement web services" implies you will create a service, it sound like you just want to call a web service. You could say "leverage web services" if you need it to be business speak complaint.

The harder way. If you can't add on any additional libraries use java.net.HttpURLConnection.

The easier way. If you can add libraries use the Jersey client API. http://jersey.java.net/nonav/documentation/latest/user-guide.html#client-api

Java EE 7 will include an official client API, EE 6 only included the REST server-side API.

But you should prefer the XML content over the JSON content yourself. JSON is great because it is easy for JavaScript to parse. Java has more ways to parse XML than it does JSON. If you really want to use JSON you could look at something like http://jettison.codehaus.org/

Since you're creating a web app that needs to do HTTP request handling... Start with either Tomcat or Jetty, and Apache HTTP Client, and use a JSON library such as available from json.org.

If you are familiar with maven, you could get all this wrapped up and building within 10 minutes. Otherwise, you'll have to build the webapp and handle dependencies yourself.

If you are on Java EE 7 and want to use the included JAX-RS 2.0 API then have a look at https://github.com/tobiasdenzler/jee7-rest-crud . Its a simple CRUD project using JSON.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM