Skip to content

rodrigogdea/simple-rest-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Rest Client

Is a simple rest client wrapping apache http client.

Installing

    <dependency>
        <groupId>org.rga</groupId>
        <artifactId>simple-rest-client_2.11</artifactId>
        <version>1.0</version>
    </dependency>

Usage

GET

    URL url = new URL("https://somehost:3334");
    Response response = new SimpleRestClient(url, true).get("/").request();

    assertTrue(response.code() == 200);

POST

        URL url = new URL("http://other:3333");
        Response response = new SimpleRestClient(url, false)
                .post("contactos")
                .header("Content-Type", "application/json; charset=UTF-8")
                .body("{\"value\":3}")
                .request();

        String result = response.asString();

PUT

        URL url = new URL("http://localhost:3333");
        Response response = new SimpleRestClient(url, false)
                .put("contactos", "23")
                .header("Content-Type", "application/json; charset=UTF-8")
                .body("{\"value\":3}")
                .request();

        String result = response.asString();

With Authentication

        URL url = new URL("http://localhost:3333");
        Response response =  new SimpleRestClient(url)
                 .withAuth("user", "pass")
                 .get("").request();

        String result = response.asString();

About

A very simple rest client wrapping apache http client.

Resources

License

Stars

Watchers

Forks

Packages

No packages published