How to create a REST client to POST a JSON object to a server and receive the data in Java

I just went through a lot of internet search in order to do exactly what the title says, looks like in the Java world you need to have always a IDE like Eclipse, or even worse, Netbeans, but sometimes I just need to test a concept and I don’t want to create a project for it.

In this case I just wanted to make a simple REST client posting a JSON object and receiving the information, lots of posts uses libraries, frameworks and all kind of stuffs, but I wanted to make it the simpler possible so, here’s my code:

Keep in mind the commands on the instructions:

This command compiles the code and includes the JAR in order to check for the classes
javac -cp lib/java-json.jar
This commands runs the code but also includes the JAR and the path where the code is
java -cp lib/java-json.jar:./ JavaRestClientTest


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s