{"id":1842,"date":"2012-09-11T13:00:00","date_gmt":"2012-09-11T13:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/simple-rest-client-in-java.html"},"modified":"2018-01-09T15:37:54","modified_gmt":"2018-01-09T13:37:54","slug":"simple-rest-client-in-java","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html","title":{"rendered":"Simple REST client in Java"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">Today most of the mobile applications that used to communicate to some server use <a href=\"http:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\" rel=\"wikipedia\" target=\"_blank\" title=\"Representational state transfer\">REST<\/a> services. These services are also common practice to use with JavaScript or jQuery. Right now I know 2 ways to create client for REST service in java and in this article I will try to demonstrate both the ways I know hoping that it will help someone in some way. <\/p>\n<p><strong>1. Using Apache HttpClient<\/strong><\/p>\n<p>The Apache HttpClient library simplifies handling HTTP requests. To use this library you have to download the binaries with dependencies from <a href=\"http:\/\/hc.apache.org\/httpclient-3.x\" target=\"_blank\" title=\"Apache HttpClient\">their website<\/a>.<br \/>\nHere is the code for HTTP GET method:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;bPg3NMopy8SOwFxv&#8217;]<\/p>\n<pre class=\"brush:java\">import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport org.apache.http.HttpResponse;\r\nimport org.apache.http.client.ClientProtocolException;\r\nimport org.apache.http.client.HttpClient;\r\nimport org.apache.http.client.methods.HttpGet;\r\nimport org.apache.http.impl.client.DefaultHttpClient;\r\npublic class Test {\r\n public static void main(String[] args) throws ClientProtocolException, IOException {\r\n  HttpClient client = new DefaultHttpClient();\r\n  HttpGet request = new HttpGet('http:\/\/restUrl');\r\n  HttpResponse response = client.execute(request);\r\n  BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));\r\n  String line = '';\r\n  while ((line = rd.readLine()) != null) {\r\n    System.out.println(line);\r\n  }\r\n }\r\n}<\/pre>\n<p>And for Post method; for sending simple string in post:      <\/p>\n<pre class=\"brush:java\">import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport org.apache.http.HttpResponse;\r\nimport org.apache.http.client.ClientProtocolException;\r\nimport org.apache.http.client.HttpClient;\r\nimport org.apache.http.client.methods.HttpPost;\r\nimport org.apache.http.entity.StringEntity;\r\nimport org.apache.http.impl.client.DefaultHttpClient;\r\npublic class Test {\r\n public static void main(String[] args) throws ClientProtocolException, IOException {\r\n  HttpClient client = new DefaultHttpClient();\r\n  HttpPost post = new HttpPost('http:\/\/restUrl');\r\n  StringEntity input = new StringEntity('product');\r\n  post.setEntity(input);\r\n  HttpResponse response = client.execute(post);\r\n  BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));\r\n  String line = '';\r\n  while ((line = rd.readLine()) != null) {\r\n   System.out.println(line);\r\n  }\r\n }\r\n}<\/pre>\n<p>You can also send full       <a href=\"http:\/\/en.wikipedia.org\/wiki\/JSON\" rel=\"homepage\" target=\"_blank\" title=\"JSON\">JSON<\/a> or       <a href=\"http:\/\/en.wikipedia.org\/wiki\/XML\" rel=\"homepage\" target=\"_blank\" title=\"XML\">XML<\/a> of a       <a href=\"http:\/\/en.wikipedia.org\/wiki\/Plain_Old_Java_Object\" rel=\"wikipedia\" target=\"_blank\" title=\"Plain Old Java Object\">POJO<\/a> by putting String representing JSON or XML as a parameter of StringEntity and then set the input content type. Something like this:      <div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">StringEntity input = new StringEntity('{\\'name1\\':\\'value1\\',\\'name2\\':\\'value2\\'}'); \/\/here instead of JSON you can also have XML\r\ninput.setContentType('application\/json');<\/pre>\n<p>For JSON you can use JSONObject to create string representation of JSON.      <\/p>\n<pre class=\"brush:java\">JSONObject json = new JSONObject();\r\njson.put('name1', 'value1');\r\njson.put('name2', 'value2');\r\nStringEntity se = new StringEntity( json.toString());<\/pre>\n<p>And for sending multiple parameter in post request:      <\/p>\n<pre class=\"brush:java\">import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\nimport org.apache.http.HttpResponse;\r\nimport org.apache.http.client.ClientProtocolException;\r\nimport org.apache.http.client.HttpClient;\r\nimport org.apache.http.client.entity.UrlEncodedFormEntity;\r\nimport org.apache.http.client.methods.HttpPost;\r\nimport org.apache.http.impl.client.DefaultHttpClient;\r\nimport org.apache.http.message.BasicNameValuePair;\r\npublic class Test {\r\n public static void main(String[] args) throws ClientProtocolException, IOException {\r\n  HttpClient client = new DefaultHttpClient();\r\n  HttpPost post = new HttpPost('http:\/\/restUrl');\r\n  List nameValuePairs = new ArrayList(1);\r\n  nameValuePairs.add(new BasicNameValuePair('name', 'value')); \/\/you can as many name value pair as you want in the list.\r\n  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));\r\n  HttpResponse response = client.execute(post);\r\n  BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));\r\n  String line = '';\r\n  while ((line = rd.readLine()) != null) {\r\n   System.out.println(line);\r\n  }\r\n }\r\n}\r\n<\/pre>\n<p><strong>2. Using Jersey<\/strong>       <\/p>\n<p><a href=\"http:\/\/jersey.java.net\/\" target=\"_blank\" title=\"Jersey\">Jersey<\/a> is the reference implementation for<a href=\"http:\/\/jcp.org\/aboutJava\/communityprocess\/final\/jsr311\/index.html\" target=\"_blank\" title=\"JSR 311 specification\">JSR-311<\/a> specification, the specification of REST support in Java. Jersey contains basically a REST server and a REST client. it provides a library to communicate with the server producing REST services. For http get method:<\/p>\n<pre class=\"brush:java\">import java.io.IOException;\r\nimport javax.ws.rs.core.MediaType;\r\nimport javax.ws.rs.core.UriBuilder;\r\nimport org.apache.http.client.ClientProtocolException;\r\nimport com.sun.jersey.api.client.Client;\r\nimport com.sun.jersey.api.client.WebResource;\r\nimport com.sun.jersey.api.client.config.ClientConfig;\r\nimport com.sun.jersey.api.client.config.DefaultClientConfig;\r\npublic class Test {\r\n public static void main(String[] args) throws ClientProtocolException, IOException {\r\n  ClientConfig config = new DefaultClientConfig();\r\n  Client client = Client.create(config);\r\n  WebResource service = client.resource(UriBuilder.fromUri('http:\/\/restUrl').build());\r\n  \/\/ getting XML data\r\n  System.out.println(service. path('restPath').path('resourcePath').accept(MediaType.APPLICATION_JSON).get(String.class));\r\n  \/\/ getting JSON data\r\n  System.out.println(service. path('restPath').path('resourcePath').accept(MediaType.APPLICATION_XML).get(String.class));\r\n }\r\n}<\/pre>\n<p>There are also other media formats in which you can get the response like PLAIN or HTML.<br \/>\nAnd for HTTP POST method:      <\/p>\n<pre class=\"brush:java\">import java.io.IOException;\r\nimport javax.ws.rs.core.MediaType;\r\nimport javax.ws.rs.core.MultivaluedMap;\r\nimport javax.ws.rs.core.UriBuilder;\r\nimport org.apache.http.client.ClientProtocolException;\r\nimport com.sun.jersey.api.client.Client;\r\nimport com.sun.jersey.api.client.ClientResponse;\r\nimport com.sun.jersey.api.client.WebResource;\r\nimport com.sun.jersey.api.client.config.ClientConfig;\r\nimport com.sun.jersey.api.client.config.DefaultClientConfig;\r\nimport com.sun.jersey.core.util.MultivaluedMapImpl;\r\npublic class Test {\r\n public static void main(String[] args) throws ClientProtocolException, IOException {\r\n  ClientConfig config = new DefaultClientConfig();\r\n  Client client = Client.create(config);\r\n  WebResource webResource = client.resource(UriBuilder.fromUri('http:\/\/restUrl').build());\r\n  MultivaluedMap formData = new MultivaluedMapImpl();\r\n  formData.add('name1', 'val1');\r\n  formData.add('name2', 'val2');\r\n  ClientResponse response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, formData);\r\n  System.out.println('Response ' + response.getEntity(String.class));\r\n }\r\n}<\/pre>\n<p>If you are using your POJO in the POST then you can do something like following:      <\/p>\n<pre class=\"brush:java\">ClientResponse response = webResource.path('restPath').path('resourcePath').\r\ntype(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, myPojo);\r\nSystem.out.println('Response ' + response.getEntity(String.class));<\/pre>\n<p>Here myPojo is an instance of custom POJO class.<br \/>\nYou can also use Form class from Jersey to submit multiple parameters in POST request:      <\/p>\n<pre class=\"brush:java\">import java.io.IOException;\r\nimport javax.ws.rs.core.MediaType;\r\nimport javax.ws.rs.core.UriBuilder;\r\nimport org.apache.http.client.ClientProtocolException;\r\nimport com.sun.jersey.api.client.Client;\r\nimport com.sun.jersey.api.client.ClientResponse;\r\nimport com.sun.jersey.api.client.WebResource;\r\nimport com.sun.jersey.api.client.config.ClientConfig;\r\nimport com.sun.jersey.api.client.config.DefaultClientConfig;\r\nimport com.sun.jersey.api.representation.Form;\r\npublic class Test {\r\n public static void main(String[] args) throws ClientProtocolException, IOException {\r\n  ClientConfig config = new DefaultClientConfig();\r\n  Client client = Client.create(config);\r\n  WebResource service = client.resource(UriBuilder.fromUri('http:\/\/restUrl').build());\r\n  Form form = new Form();\r\n  form.add('name1', 'value1');\r\n  form.add('name2', 'value1');\r\n  ClientResponse response = service.path('restPath').path('resourcePath').\r\n  type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, form);\r\n  System.out.println('Response ' + response.getEntity(String.class));\r\n }\r\n}\r\n<\/pre>\n<p>Happy coding and don&#8217;t forget to share!<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/harryjoy.me\/2012\/09\/08\/simple-rest-client-in-java\/\">Simple REST client in java<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Harsh Raval at the <a href=\"http:\/\/harryjoy.me\/\">harryjoy<\/a> blog.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with JavaScript or jQuery. Right now I know 2 ways to create client for REST service in java and in this article I will try to demonstrate both the ways I &hellip;<\/p>\n","protected":false},"author":84,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[219,54],"class_list":["post-1842","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jersey","tag-restful-web-services"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Simple REST client in Java - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simple REST client in Java - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-11T13:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T13:37:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Harsh Raval\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harsh Raval\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html\"},\"author\":{\"name\":\"Harsh Raval\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0fdcd967c00c2e84d5420b020528d94c\"},\"headline\":\"Simple REST client in Java\",\"datePublished\":\"2012-09-11T13:00:00+00:00\",\"dateModified\":\"2018-01-09T13:37:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html\"},\"wordCount\":301,\"commentCount\":18,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"Jersey\",\"RESTful Web Services\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html\",\"name\":\"Simple REST client in Java - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2012-09-11T13:00:00+00:00\",\"dateModified\":\"2018-01-09T13:37:54+00:00\",\"description\":\"Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/09\\\/simple-rest-client-in-java.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Simple REST client in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0fdcd967c00c2e84d5420b020528d94c\",\"name\":\"Harsh Raval\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a89c300d17c60238f78f7dacc84b3ad765872b485a731c5a422b86a2cdd2b2e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a89c300d17c60238f78f7dacc84b3ad765872b485a731c5a422b86a2cdd2b2e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a89c300d17c60238f78f7dacc84b3ad765872b485a731c5a422b86a2cdd2b2e?s=96&d=mm&r=g\",\"caption\":\"Harsh Raval\"},\"sameAs\":[\"http:\\\/\\\/harryjoy.me\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/harsh-raval\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simple REST client in Java - Java Code Geeks","description":"Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html","og_locale":"en_US","og_type":"article","og_title":"Simple REST client in Java - Java Code Geeks","og_description":"Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with","og_url":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-09-11T13:00:00+00:00","article_modified_time":"2018-01-09T13:37:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Harsh Raval","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Harsh Raval","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html"},"author":{"name":"Harsh Raval","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0fdcd967c00c2e84d5420b020528d94c"},"headline":"Simple REST client in Java","datePublished":"2012-09-11T13:00:00+00:00","dateModified":"2018-01-09T13:37:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html"},"wordCount":301,"commentCount":18,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["Jersey","RESTful Web Services"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html","url":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html","name":"Simple REST client in Java - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2012-09-11T13:00:00+00:00","dateModified":"2018-01-09T13:37:54+00:00","description":"Today most of the mobile applications that used to communicate to some server use REST services. These services are also common practice to use with","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/09\/simple-rest-client-in-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Simple REST client in Java"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0fdcd967c00c2e84d5420b020528d94c","name":"Harsh Raval","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0a89c300d17c60238f78f7dacc84b3ad765872b485a731c5a422b86a2cdd2b2e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0a89c300d17c60238f78f7dacc84b3ad765872b485a731c5a422b86a2cdd2b2e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0a89c300d17c60238f78f7dacc84b3ad765872b485a731c5a422b86a2cdd2b2e?s=96&d=mm&r=g","caption":"Harsh Raval"},"sameAs":["http:\/\/harryjoy.me\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/harsh-raval"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/84"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=1842"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1842\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=1842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=1842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=1842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}