android-rest-client


Source link: https://github.com/darko1002001/android-rest-client

Follow to public page for more info

android-rest-client

A simple rest API client library

Check for the latest version on Maven Central

used libraries

Main Rest client uses OKHTTP from square https://github.com/square/okhttp

to provide HTTP layer compatibility across android OS versions and manufacturers

Additions library uses:

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.3.0</version>  </dependency>  <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.3.0</version>  </dependency>  <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.0</version>  </dependency>  <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>  </dependency> 

Overview

Can be used to run synchronous or asynchronous requests towards your API. There is a service class that handles request execution by 2 kinds of thread pools (choice can specified in the request implementation) either a single thread executor or a fixed size executor. Each of the executors is backed by a priority queue which means each individual request can have an execution priority set.

You can also provide your own service class which will handle the requests, extend from the current ones etc...

By default authorization is handled by setting an OAuth token in the header, but can be replaced with a custom implementation.

Note: The process of getting an oauth token from the server is not a part of this library implementation and have to be set according to the specification for your webservice.

Usage:

Look at the demo project included in this repo for details.

There is another sample project with an older version of android-rest-client found here: https://github.com/darko1002001/sync-notes-android

Steps to setup the library

  1. Import the lib project into your workspace and add it as a library project
  2. Look into the demo project manifest and copy the definitions
  3. Check the App.java class inside the Demo project on how to configure the library.

Adding just the JAR files

The library can be added inside /libs as a JAR. The dependencies include a version of Jackson for parsing JSON requests. you can use the regular jar and add your own parsers if the responses aren't JSON or you want to use a different library for parsing them.

Manifest Declarations

  <uses-permission android:name="android.permission.INTERNET" />
 <uses-sdk android:minSdkVersion="14" />
 <application>
<service android:name="com.araneaapps.android.libs.asyncrunners.services.ExecutorService"></service>
</application> 

Configuration

The library needs to be configured in a class extending Application (look into the demo project for specifics).

RestClientConfiguration builder = new RestClientConfiguration.ConfigurationBuilder()
  .setAuthenticationProvider(new AuthenticationProvider() {

 @Override

 public void authenticateRequest(RestClientRequest client) {

// YOu can add parameters or headers which will be attached to each request

 
}

  
}
)
  .create();
  RestClientConfiguration.init(this, builder);
 

Note - If including this library with gradle will automatically merge your manifest with the one with the library. The lib is published as AAR.

Calling requests (From the demo project)

```  //----------------------------------  TwitterService.getUsersTwitterRequest("android").setCallback(new HttpCallbackImplementation())
  .executeAsync();
  //----------------------------------
// Callback returning your defined type  private final class HttpCallbackImplementation implements HttpCallback<UserModel> {

@Override
  public void onSuccess(UserModel responseData, ResponseStatus responseCode) {

textViewResponse.setText(responseData.toString());

  
}

@Override
  public void onHttpError(ResponseStatus responseCode) {

Toast.makeText(getApplicationContext(),

  responseCode.getStatusCode() + " " + responseCode.getStatusMessage(),

  Toast.LENGTH_LONG).show();

}
 
}
 ``` 

Two callback methods are created each executing by default in the Android UI Thread so you don't have to implement the logic for switching back to UI from another thread.

SDK that uses This library:

Chute https://github.com/chute/Chute-SDK-V2-Android

Use of Authentication Provider

Look at the demo project to see how the Authentication Provider can be set. Use this if you need to define a custom logic (Parameters and/or headers that will be appended on each request). You can also specify a provider for individual requests.

Changelog:

Release 2.2.0

Updated version of OKHTTP to 2.+ Changed the requests to RestClientRequest.class which handles all the request types. Added the option to run requests without a parser or a callback The callback can be set externally when creating the request

Release 1.7.0

Added RestClientConfiguration so all the global configuration is done through it.

Release 1.6.0

Breaking changes

Added response status to success callback implementation

Release 1.4.0

Created a new project additions which now has some helper libraries and classes such as Jackson JSON parser, IOUtils from apache etc... Moved the async part (Service with executors) of the library to a new more general project on github not specific to just HTTP. HttpRequestStore.init(context) is now replaced with AsyncRunners.init(context) which will provide a wrapping layer around the code that should be initialized in the App class HttpRequest now extends Runnable interface Added the option to override a handleStatus method in BaseHttpRequestImpl to be able to do custom result handing based on the status (see demo for sample)

Release 1.3.5

Fix issue with add param with token provider Added socket timeout and connection timeout setters by calling getClient().set... inside any of the request classes.

Release 1.3.0

Added Entity body requests which are now the base class for the String body request. Opens options to add FileEntity body which enables you to upload streams from files. File Requests also include a progress listener which you can set if you want to track the progress. Added File Parser which save the response stream to a specified file location.

Release 1.1.0

Reworked the HttpRequestParser to return an InputStream instead of a String. Use StringResponseParser (extend or use directly) to get the input stream into a String

Resources

A cool gallery view with vertical smooth animation which shows content more attractive.

An open source camera for google glass. This is a an alternative to the default camera on Glass. CuXtom Cam provides you the default behaviour along with some special feature.

Endoscope allows you to fast link two android devices and stream live video from camera one device to another. Video stream is over Wi-Fi. One device hosts live stream and another connect to it.

An example with floating view.

A line chart library.

A library that uses technologies like artificial Intelligence, machine learning, and deep learning to make developers understand the content that they are displaying in their app.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes