restclient

Java Http Client for MicroServices

License

License

Categories

Categories

Java Languages CLI User Interface Utility General Purpose Libraries
GroupId

GroupId

com.gsssoftwaresolution.java.utility.restfulservices
ArtifactId

ArtifactId

easyrestfulclient
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

restclient
Java Http Client for MicroServices
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/gsssoftwaresolution/easyrestfulclient.git

Download easyrestfulclient

How to add to project

<!-- https://jarcasting.com/artifacts/com.gsssoftwaresolution.java.utility.restfulservices/easyrestfulclient/ -->
<dependency>
    <groupId>com.gsssoftwaresolution.java.utility.restfulservices</groupId>
    <artifactId>easyrestfulclient</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.gsssoftwaresolution.java.utility.restfulservices/easyrestfulclient/
implementation 'com.gsssoftwaresolution.java.utility.restfulservices:easyrestfulclient:1.0.0'
// https://jarcasting.com/artifacts/com.gsssoftwaresolution.java.utility.restfulservices/easyrestfulclient/
implementation ("com.gsssoftwaresolution.java.utility.restfulservices:easyrestfulclient:1.0.0")
'com.gsssoftwaresolution.java.utility.restfulservices:easyrestfulclient:jar:1.0.0'
<dependency org="com.gsssoftwaresolution.java.utility.restfulservices" name="easyrestfulclient" rev="1.0.0">
  <artifact name="easyrestfulclient" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.gsssoftwaresolution.java.utility.restfulservices', module='easyrestfulclient', version='1.0.0')
)
libraryDependencies += "com.gsssoftwaresolution.java.utility.restfulservices" % "easyrestfulclient" % "1.0.0"
[com.gsssoftwaresolution.java.utility.restfulservices/easyrestfulclient "1.0.0"]

Dependencies

compile (4)

Group / Artifact Type Version
com.fasterxml.jackson.dataformat : jackson-dataformat-xml jar 2.7.4
org.apache.directory.studio : org.apache.commons.io jar 2.4
com.fasterxml.jackson.core : jackson-databind jar 2.6.0
org.apache.httpcomponents : httpclient jar 4.4

test (2)

Group / Artifact Type Version
com.github.tomakehurst : wiremock jar 1.58
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

EasyRestfulClient

It is java library developed on top of Apache HTTP library and JDK executor framework. It has capability to execute multiple restful requests concurrently in very easy way.

Features

  1. Supports HTTP GET and POST methods.
  2. Concurrent execution of requests.
  3. Auto conversion request and response to JSON and XML formats.
  4. Easy Request creation.

How to use

Add Repository to project POM.xml

	<repositories>
		<repository>
			<id>EasyRestFulclientRepository</id>
			<url>https://repo1.maven.org/maven2</url>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
		...
	</repositories>
    

Add Dependency in POM.xml

	<dependency>
		<groupId>com.gsssoftwaresolution.java.utility.restfulservices</groupId>
		<artifactId>easyrestfulclient</artifactId>
		<version>1.0.0</version>
	</dependency>
	

Create RestClientManager Object

	RestClientManager restClient=new RestClientManager(3);

Create Request

Depending upon Content_type header value, library converts request java object to either json or xml. Likewise upon Accept header value, library build response either from json or xml response.

GET

    
	Map<String,String> headers=new HashMap<>();
	String requestUrl="http://localhost:8080/getTestPage";
	headers.put(Constant.CONTENT_TYPE, Constant.MEDIATYPE_JSON);
	headers.put(Constant.ACCEPT, Constant.MEDIATYPE_JSON);
	responseClass=Response.class;
	Request request=new GetRequest(requestUrl,headers, responseClass);

POST

      
	Map<String,String> headers=new HashMap<>();
	String requestUrl="http://localhost:8080/getTestPage";
	headers.put(Constant.CONTENT_TYPE, Constant.MEDIATYPE_JSON);
	headers.put(Constant.ACCEPT, Constant.MEDIATYPE_JSON);
	responseClass=Response.class;
	requestBody=new RequestBody();
	Request request=new PostRequest(requestUrl, headers, requestBody, responseClass);

Make Request and Collect Response

	Response response=(Response)restClient.getData(request);

Make multiple concurrent requests

	//  First request	with JSON format  
	requestUrl="http://localhost:8080/getPerson1";
	headers.put(Constant.CONTENT_TYPE, Constant.MEDIATYPE_JSON);
	headers.put(Constant.ACCEPT, Constant.MEDIATYPE_JSON);
	responseClass=Response1.class;
	requestBody=new RequestBody1();
	((RequestBody1)requestBody).setName("postDummyName1");
	Request request1=new PostRequest(requestUrl,headers, requestBody, responseClass);
	  
	// Second request with XML formats
	requestUrl="http://localhost:8080/getPerson2";
	headers.put(Constant.CONTENT_TYPE, Constant.MEDIATYPE_XML);
	headers.put(Constant.ACCEPT, Constant.MEDIATYPE_XML);
	responseClass=Response2.class;
	Request request2=new GetRequest(requestUrl,headers, responseClass);
	  
	// Third request with JSON format
	requestUrl="http://localhost:8080/getPerson3";
	headers.put(Constant.CONTENT_TYPE, Constant.MEDIATYPE_JSON);
	headers.put(Constant.ACCEPT, Constant.MEDIATYPE_JSON);
	responseClass=Response3.class;
	requestBody=new RequestBody3();
	((RequestBody3)requestBody).setName("postDummyName3");
	Request request3=new PostRequest(requestUrl, headers, requestBody, responseClass);
	  
	List<Request> requests=new ArrayList<Request>();
	requests.add(request1);
	requests.add(request2);
	requests.add(request3);
	  
	List<Object> responses=(List<Object>)restClient.getData(requests);
	

Versions

Version
1.0.0