Search in sources :

Example 1 with RequestEntity

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);
}
Also used : HttpClient(com.tvd12.ezyhttp.client.HttpClient) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Example 2 with RequestEntity

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);
}
Also used : RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity) MultiValueMap(com.tvd12.ezyhttp.core.data.MultiValueMap) Test(org.testng.annotations.Test)

Example 3 with RequestEntity

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) User(org.youngmonkeys.example.ezyhttp.website.user_management.entity.User) HttpClient(com.tvd12.ezyhttp.client.HttpClient) PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) Request(com.tvd12.ezyhttp.client.request.Request) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Example 4 with RequestEntity

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);
}
Also used : GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) Request(com.tvd12.ezyhttp.client.request.Request) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Example 5 with RequestEntity

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) Customer(com.tvd12.ezyhttp.client.test.request.Customer) HttpClient(com.tvd12.ezyhttp.client.HttpClient) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Aggregations

RequestEntity (com.tvd12.ezyhttp.client.request.RequestEntity)10 Test (org.testng.annotations.Test)5 HttpClient (com.tvd12.ezyhttp.client.HttpClient)4 MultiValueMap (com.tvd12.ezyhttp.core.data.MultiValueMap)4 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)3 GetRequest (com.tvd12.ezyhttp.client.request.GetRequest)2 Request (com.tvd12.ezyhttp.client.request.Request)2 HelloRequest (com.tvd12.ezyhttp.client.test.request.HelloRequest)2 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)1 Customer (com.tvd12.ezyhttp.client.test.request.Customer)1 ResponseEntity (com.tvd12.ezyhttp.core.response.ResponseEntity)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 User (org.youngmonkeys.example.ezyhttp.website.user_management.entity.User)1