Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Latest commit

 

History

History
31 lines (24 loc) · 1.09 KB

README.md

File metadata and controls

31 lines (24 loc) · 1.09 KB

RESTclient-Android

This library is designed to greatly assist consuming RESTful webservices. Originally I started by using the library listed in the contributions. I then modified to DRY up the script, added PUT and DELETE verbs, HTTP basic authentication, and a JSON body.

Usage

The code below is an example using a GET request to grab JSON from the server

RestClient client = new RestClient(webServiceUrl);
client.addBasicAuthentication(username, password);
try {
	client.execute(RequestMethod.GET);
	if (client.getResponseCode() != 200) {
		//return server error
		return client.getErrorMessage();
	}
	//return valid data
	JSONObject jObj = new JSONObject(client.getResponse());
	return jObj.toString();
} catch(Exception e) {
	return e.toString();
}

Contributions

http://lukencode.com/2010/04/27/calling-web-services-in-android-using-httpclient/

##RESTclient-Example This example uses a service to consume a webservice in the background and update the activity if its in use, or store the data for the next time the user is active.

License

Release under the Apache 2 license.