A simple http client using only java.net classes, thus making it compatible with AppEngine's urlFetch service
Java CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
classes
javadoc
lib
src
.DS_Store
.gitignore
NOTICE.md
README.md

README.md

http-client

I wrote this simple Http client to use in my AppEngine applications that use the urlFetch service. Because it runs in AppEngine, it can only use the native Java classes (in java.net). The goal was to make a very simple Http client that I can use to call external RESTful API's. I wanted to hide all of the complexities behind an intuitive interface.

I also used generics so that the method calls can be chained together.

How to use it

Here's an example of a simple GET request:

        Response httpResponse = new Request("http://example.com")
                .getResource();

        String responseBody = httpResponse.getBody();

Here's a GET request with a header and a query parameter specified:

        Response httpResponse = new Request("http://example.com")
                .addHeader("x-my-header", "foobar")
                .addQueryParameter("foo", "bar")
                .getResource();

        String responseBody = httpResponse.getBody();

Here's a more complicated example of a POST request with query parameters and a Content-Type header:

        // Posts a simple JSON object to the server
        Response httpResponse = new Request("http://example.com")
                .addHeader("Content-Type", "application/json")
                .addQueryParameter("foo", "bar")
                .setBody("{foo: 'bar'}")
                .postResource();

        String responseBody = httpResponse.getBody();