use of com.tvd12.ezyhttp.client.request.RequestEntity in project ezyhttp by youngmonkeys.
the class CustomerApisTest method getCustomerTest.
protected static void getCustomerTest() throws Exception {
HttpClient client = HttpClient.builder().build();
RequestEntity entity = RequestEntity.builder().header("token", "123").build();
GetRequest request = new GetRequest().setURL("http://localhost:8081/api/v1/customer/hello/dung").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.request.RequestEntity in project ezyhttp by youngmonkeys.
the class RequestEntityTest method buildMultiMapBody.
@Test
public void buildMultiMapBody() {
// given
Map<String, List<String>> data = new HashMap<>();
data.put("1", Arrays.asList("hello", "world"));
data.put("2", Arrays.asList("foo", "bar"));
data.put("3", Collections.singletonList("monkey"));
data.put(Headers.CONTENT_TYPE, Collections.singletonList(ContentTypes.APPLICATION_JSON));
RequestEntity sut = RequestEntity.builder().body(new MultiValueMap(data)).build();
// when
// then
Map<String, String> expectation = new HashMap<>();
expectation.put("1", "hello;world");
expectation.put("2", "foo;bar");
expectation.put("3", "monkey");
expectation.put(Headers.CONTENT_TYPE, ContentTypes.APPLICATION_JSON);
Asserts.assertEquals(expectation, sut.getBody());
System.out.println(sut);
}
use of com.tvd12.ezyhttp.client.request.RequestEntity in project ezyfox-examples by tvd12.
the class ApiAddUserTest method main.
public static void main(String[] args) throws Exception {
HttpClient httpClient = HttpClient.builder().build();
User body = new User();
body.setUsername("tvd12");
body.setPassword("123456");
RequestEntity requestEntity = RequestEntity.body(body);
Request request = new PostRequest().setURL(API_URL + "add").setEntity(requestEntity).setResponseType(Boolean.class).setResponseType(StatusCodes.CONFLICT, String.class);
Boolean response = httpClient.call(request);
System.out.println("add user reponse: " + response);
}
use of com.tvd12.ezyhttp.client.request.RequestEntity in project ezyfox-examples by tvd12.
the class ApiGetUserTest method main.
public static void main(String[] args) throws Exception {
HttpClientProxy httpClient = HttpClientProxy.builder().build();
httpClient.start();
RequestEntity entity = RequestEntity.builder().build();
Request helloRequest = new GetRequest().setURL(API_URL + "tvd12").setEntity(entity).setResponseType(String.class).setResponseType(StatusCodes.NOT_FOUND, String.class);
String response = httpClient.call(helloRequest, 10000);
System.out.println("get user response: " + response);
}
use of com.tvd12.ezyhttp.client.request.RequestEntity in project ezyhttp by youngmonkeys.
the class CustomerApisTest method addCustomerTest.
protected static void addCustomerTest() throws Exception {
HttpClient client = HttpClient.builder().build();
Customer body = new Customer();
body.setName("dung");
body.setAge(28);
RequestEntity entity = RequestEntity.of(body).header("token", "123").build();
PostRequest request = new PostRequest().setURL("http://localhost:8081/api/v1/customer/add").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
Aggregations