Skip to content

A simple http client using only java.net classes, thus making it compatible with AppEngine's urlFetch service

Notifications You must be signed in to change notification settings

JoeJErnst/http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

A simple http client using only java.net classes, thus making it compatible with AppEngine's urlFetch service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published