APIServiceLibrary - Minimized API library which is used call the server request in andorid.

Overview

Minimized API Service Library

This is a optimized custom library for server communication. References taken from VOLLEY library. We can reduce the code for making api calls when using this library. All references are taken from Google's Official Volley.

Features:

  1. Added custom listeners to handle the responses in easy way
  2. Added Progress bar when getting response from server.(can disable by passing false in request)
  3. Success and Failure response are captured in Logcats(Log.Info)
  4. Circular imageview
  5. Used API TAGS to identify multiple requests on single activity.
  6. Added ResponseHeaders in response
  7. File upload

Screenshot Screenshot

HOW TO USE

Step 1:

Add this to app gradle


dependencies {
    implementation 'com.libRG.volley:apiservices:1.7'
}


Step 2: Implement ActivityResponseListener on activity for getting success & failure response from server

Implementation Steps in Activity


public class MainActivity extends AppCompatActivity implements ActivityResponseListener{

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //Setting authentication tokens for request - set this code into base activity

        //HashMap<String, String> headerParams = new HashMap<>();
        //headerParams.put("key", "value");
        //ApiService.setHeaders(headerParams);
        
        sendRequest();
    }

 private void sendRequest() { // tag is used to identify the API requests - when multiple requests are used.
        String url = "http://maps.googleapis.com/maps/api/geocode/json?address=560078";
        ApiService.StringRequest(this, 1, url, null, "GET_ADDRESS", true);
    }
    
  public void setImage(String imageURL, ImageView imageView) {
  
        ApiService.getImageLoader(this).get(imageURL, ImageLoader.getImageListener(imageView, R.mipmap.ic_launcher_round,R.mipmap.ic_launcher));
 }
    
    
  @Override
    public <T> void onResponse(T response, String tagName, JSONObject responseHeaders) {//responseHeaders is used to catch the network header params like auth key and value
        
        if (tagName.equals("GET_ADDRESS")) {
        Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();
        }
        
    }

    @Override
    public void onError(Object error, String tagName) {
        Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
    }
    
}



APIServiceLibrary Provides variety of implementations of Request.

  1. StringRequest
  2. JsonObjectRequest
  3. JsonArrayRequest
  4. File Upload
  5. ImageRequest

Explanation of code:

   HashMap<String, String> input  =new HashMap<String, String>() 
   input.put("key", "value");
   
   ApiService.StringRequest(this, 1, url, input, "GET_ADDRESS", true);
    
   StringRequest & JSONObjectRequest method Params :
    
   1. this           -->   It is used receive the callback from server response.(passing context to intialize the request)
   2. 0 or 1         -->   This is request type either POST or GET etc.(should pass integer values)
   3. url            -->   This is request url of server
   4. input          -->   Pass request input parameters based on method types(GET or POST, if GET method pass null)
                           (if JSON request pass json input else pass formdata)
   5. GET_ADDRESS    -->   This is Request TAG to identify and parse the specific response from server
   6. true           -->   This is used to show progress bar when getting data from server.(pass false if not required)
   
 **File upload:**
 
   ApiService.UploadFile(this, 1, url, input_params, file, "file_key", "tag_name", true);
   
   ApiService.UploadFile(this, 1, url, input_params, HashMap<String, File> fileList, "file_key", "tag_name", true);
   
   1. this           -->   It is used receive the callback from server response.(passing context to intialize the request)
   2. 0 or 1         -->   This is request type either POST or GET etc.(should pass integer values)
   3. url            -->   This is request url of server
   4.input_params    -->   hashmap input params
   5.file            -->   File to upload (if multiple files use Hashmap<String,File> fileList)
   6 file_key        -->   Filekey param
   7.tag_name        -->   This is Request TAG to identify and validate the specific response from server
   8.true            -->   This is used to show progress bar when getting data from server.(pass false if not required)
   
   

   
 # Setting authentication tokens for request
 
        HashMap<String, String> headerParams = new HashMap<>();
        headerParams.put("key", "value");
        ApiService.setHeaders(headerParams);
        
   Note - set these headers to appcontrollers whenever lauch the app.  
   
 # Set custom progress dialog 
   
    ApiService.setCustomDialogView(R.layout.progress_bar_dialog);
    ApiService.setCancellable(true);
 
        

Proguard Rules

Use the following suggested ProGuard settings


-keep class android.net.http.** { *; }
-dontwarn android.net.http.**

-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
-keep class com.libRG.** {*;}

References taken from Google's Volley Library

I have optimized the API request code to reduce the code implementation for api call. I used volley for server commmunication. Thanks to Volley*__*

License


Copyright 2017 Rajagopal

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


You might also like...
Movies App with Movies API
Movies App with Movies API

MoviesApp-Android 🎞 Movies app with MoviesApp API. Here i demonstrate the use of Modern Android development tools - (Kotlin, Architecture Components,

👨‍💻 A demonstration modern Android development project with Jetpack(Compose, Room, ViewModel, Navigation), Hilt and based on MVVM by using Open Sky API. ✈️ 🌍
👨‍💻 A demonstration modern Android development project with Jetpack(Compose, Room, ViewModel, Navigation), Hilt and based on MVVM by using Open Sky API. ✈️ 🌍

A demonstration modern Android development project with Jetpack(Compose, Room, ViewModel, Navigation), Hilt and based on MVVM by using Open Sky API.

A demonstration modern Android development project with Jetpack(Compose, Room, Flow, ViewModel, Navigation), Hilt and based on MVVM by using Github API.
A demonstration modern Android development project with Jetpack(Compose, Room, Flow, ViewModel, Navigation), Hilt and based on MVVM by using Github API.

A demonstration modern Android development project with Jetpack(Compose, Room, ViewModel, Navigation), Hilt and based on MVVM by using Github API.

RxJava architecture library for Android
RxJava architecture library for Android

Reference Architecture for Android using RxJava This is an ambitious reference project of what can be done with RxJava to create an app based on strea

Sample Project for Android Support Library 23.2
Sample Project for Android Support Library 23.2

SnapShot: Contains features Vector Drawable Animated Vector Drawable AppCompat DayNight theme Bottom Sheets Using BottomSheetDialog in day-night mode.

Examples for my Android GraphView library

Chart and Graph Library for Android GraphView - open source graph plotting library for Android GraphView is a library for Android to programmatically

RoboDemo is a ShowCase library for Android to demonstrate to users how a given Activity works.
RoboDemo is a ShowCase library for Android to demonstrate to users how a given Activity works.

RoboDemo RoboDemo is a ShowCase library for Android to demonstrate to users how a given Activity works. A sample is available in the download area of

Create curve bottom navigation using this library
Create curve bottom navigation using this library

Curve Bottom Bar Download Add it to your build.gradle with: allprojects { repositories { maven { url "https://jitpack.io" } } } and: d

RxJava architecture library for Android
RxJava architecture library for Android

Reference Architecture for Android using RxJava This is an ambitious reference project of what can be done with RxJava to create an app based on strea

Owner
Raja Gopal
Android Developer|Passionate Developer
Raja Gopal
Quality-Tools-for-Android 7.5 0.0 L5 Java This is an Android sample app + tests that will be used to work on various project to increase the quality of the Android platform.

Quality Tools for Android This is an Android sample app + tests that will be used to work on various project to increase the quality of the Android pl

Stéphane Nicolas 1.3k Dec 27, 2022
SquircleView is a library which provides you with Squircle views to use for buttons, views, etc.

SquircleView SquircleView is a library which provides you with Squircle views to use for buttons, views, etc. Screenshots Different kinds of buttons,

Juky 96 Dec 15, 2022
Viacheslav Veselov 0 Jul 8, 2022
A sample Android app which showcases advanced usage of Dagger among other open source libraries.

U+2020 A sample Android app which showcases advanced usage of Dagger among other open source libraries. Watch the corresponding talk or view the slide

Jake Wharton 5.7k Dec 22, 2022
A project which demonstrate how to develop a custom client on android for dribbble.com

##What is this? This is a project with custom client app on android for https://dribbble.com, which you can browse the popular icon and animation, lik

ZhangLei 599 Nov 14, 2022
A Basic Drawing App which is having Functionality of importing images from your gallery and sharing your drawing via Whatsapp , Email

Drawing-App A Basic Drawing App made in Kotlin Features of the App :) 1.you can set the size of paint Brush 2.import images from gallery 3.share it vi

MaNiSh 1 Jan 18, 2022
Quick start with the Google Maps Android API

Please note: This repository is not currently maintained, and is kept for historical purpose only. You can find an up to date tutorial here: https://g

Google Archive 234 Nov 14, 2022
This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shadows etc...

Android L preview example Description This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shad

Saul Molinero 165 Nov 10, 2022
Quick start with the Google Maps Android API

Please note: This repository is not currently maintained, and is kept for historical purpose only. You can find an up to date tutorial here: https://g

Google Archive 234 Nov 14, 2022
This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shadows etc...

Android L preview example Description This project is focused on the sample using the API's new preview version of Android-L, use of transitions, shad

Saul Molinero 165 Nov 10, 2022