GithubHelp home page GithubHelp logo

android-rest-api-client's Introduction

android-rest-api-client

A RESTful Web API Client for Android designed to make API calls with JSON easy and minimal in your code

Usage

Download the file and add your package name if required at the top of the file

To create an instance of the client call its constructor like so:

RESTAPIClient client = new RESTAPIClient("http://api.google.com/api");

The parameter passed in the constructor is the base point for all of your api calls. Future calls will only require the route path. You can change the base path at anytime after creation with:

client.changeBaseURL("http://myapi.com/api");

Now using your instance you can make all of the 4 standard GET, PUT, POST, and DELETE REST calls with the appropriate methods. See the API section for more details on these calls

client.getData("/news");
client.postData("/news", jsonBody);
client.putData("/news/article/1", jsonBody);
client.deleteData("/news/article/5");

The json response from the server is captured within the instance after the call is made. You can retrieve it either as a stringified json or as a json object. Note in this current version, the response must come back as a json object. JSONArray support is still under development

JSONObject response = client.getRawJSONObject();
String response = client.getRawResponse();

After that your ready to make another API call. At each call the previous captured json data is overwritten.

#API Create Instance:

RESTAPIClient client = new RESTAPIClient(String baseURL);

Change the Base URL

client.setBaseURL(String baseURL);

Make a GET request call

client.getData(String route);

Make a POST request call with a json body. Create a json object and assign it values. Then pass the instance to this postData method. To make a post request with an empty body, pass a new empty instance of a JSONObject. Passing null may work aswell but has not been tested

client.postData(String route, JSONObject bodyContent);

Make a POST request call with a json body. Create a json object and assign it values. Then pass the instance to this putData method. To make a post request with an empty body, pass a new empty instance of a JSONObject. Passing null may work aswell but has not been tested

client.putData(String route, JSONObject bodyContent);

Make a DELETE request call

client.deleteData(String route);

Get json Response as a String or JSONOBject. Note the server must respond with a json object

client.getRawResponse(); // returns serialized json as a string of the response
client.getRawJSONObject(); // returns JSONObject of response

android-rest-api-client's People

Contributors

bensoer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

antyp1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.