super simple library to manage http requests.

Overview

HttpAgent

super simple library to manage http requests.

Gradle

dependencies {
    implementation 'com.studioidan.httpagent:httpagent:1.0.16@aar'
}

Now see how easy it becomes with HttpAgent!

Get Request

HttpAgent.get("www.example.com/api/books")
                    .goJson(new JsonCallback() {
                        @Override
                        protected void onDone(boolean success, JSONObject jsonObject) {
                            
                        }
                    });

or you can go jsonArray like so

HttpAgent.get("www.example.com/api/books")
                    .goJsonArray(new JsonArrayCallback() {
                        @Override
                        protected void onDone(boolean success, JSONArray jsonArray) {
                            
                        }
                    });

Need to add url parameters? no problem!

HttpAgent.get("www.example.com/api/books")
                    .queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
                    .goJsonArray(new JsonArrayCallback() {
                        @Override
                        protected void onDone(boolean success, JSONArray jsonArray) {
                            
                        }
                    });

Post? Put? Delete? of course...

HttpAgent.post("www.example.com/api/books");
HttpAgent.put("www.example.com/api/books");
HttpAgent.delete("www.example.com/api/books")

Adding body is also simple...

HttpAgent.post("www.example.com/api/books")
                    .queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
                    .withBody("{name:popapp ,age:27}")
                    .goJsonArray(new JsonArrayCallback() {
                        @Override
                        protected void onDone(boolean success, JSONArray jsonArray) {

                        }
                    });

Or even more simple...

HttpAgent.post("www.example.com/api/books")
                    .queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
                    .withBody("key_1","value_1","key_2","value_2","key_N","value_N") // will be converted to json
                    .goJsonArray(new JsonArrayCallback() {
                        @Override
                        protected void onDone(boolean success, JSONArray jsonArray) {

                        }
                    });

Don't forget the headers...

HttpAgent.get("http://192.168.88.253/Video/inputs/channels/1")
                        .headers("Authorization", "Basic YWRtaW46P3V5YFZhNzAw", "Content-Type", "application/json")
                        .goString(new StringCallback() {
                            @Override
                            protected void onDone(boolean success, String stringResults) {
                                Log.d(TAG, stringResults);
                            }
                        });

Any request can be made with one of the following callbacks:

Get a string results

goString(new StringCallback() {
                        @Override
                        protected void onDone(boolean success, String results) {
                            
                        }
                    })

Get Json results

goJson(new JsonCallback() {
                        @Override
                        protected void onDone(boolean success, JSONObject jsonObject) {
                            
                        }
                    })

Get JsonArray results

goJsonArray(new JsonArrayCallback() {
                        @Override
                        protected void onDone(boolean success, JSONArray jsonArray) {

                        }
                    });

Get no results, Just send the request

go(new SuccessCallback() {
                        @Override
                        protected void onDone(boolean success) {
                            
                        }
                    })

You also have access to those on any callback

HttpAgent.post("www.example.com/api/books")
                    .queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
                    .withBody("{name:popapp ,age:27}")
                    .goJson(new JsonCallback() {
                        @Override
                        protected void onDone(boolean success, JSONObject jsonObject) {
                            getErrorMessage(); //returns error message if exists.
                            getResponseCode(); // well, it's obvious...
                            getStringResults(); // returns results as as string.
                        }
                    });
Comments
  • Force wifi

    Force wifi

    Hey! I'm trying to create an app to login to a wifi hotspot but I have a problem, when I want to submit the form the mobile data is used because the wifi connection is not "working" until you submit the form. With your library can I choose to use wifi connection to post the form instead of mobile data?

    Thanks!

    opened by ghost 1
  • error message ..

    error message ..

    java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/AsyncTaskCompat; at com.studioidan.httpagent.HttpAgent.executeSelf(HttpAgent.java:173) at com.studioidan.httpagent.HttpAgent.goJson(HttpAgent.java:158) at com.example.snapgroup6.myapplication.MainActivity.onCreate(MainActivity.java:22)

    opened by mohamadir 2
  • Posting Body (without converting request body in to json)

    Posting Body (without converting request body in to json)

    Hi

        HttpAgent.post("http://192.168.1.101:8002/dummy_file/generate_oauthSignature")
        .withBody("key_1","value_1","key_2","value_2","key_N","value_N") // will be converted to json
       .headers("Content-Type", "application/x-www-form-urlencoded")
    

    I do not want to convert body in to json as server side tech. requires key_1 = value_1 param as a post.

    opened by chiragpurohit71085 1
  • Restore files deleted in commit 83a0987

    Restore files deleted in commit 83a0987

    The source code from

    https://github.com/studioidan/HttpAgent/tree/master/httpagent/src/main

    was removed in this commit: 83a0987

    I presume this was accidental when the package name was changed from "studioidan.com.httpagent" to "com.studioidan.httpagent". This pull request restores it.

    opened by intrications 0
  • Two onDone occur in one HttpAgent.post

    Two onDone occur in one HttpAgent.post

    When I use one HttpAgent.post then two onDone occur. I use JsonCallback. First onDone return empty jsonResponse and the second onDone return filled jsonResponse from remote server API.

    opened by sainer 1
  • Source Code and Post method

    Source Code and Post method

    Hi,

    Thanks for your contribution.

    Firstly, we don't have any access to your code or you have deleted it ? I can't see any source code when I fork your project.

    Secondly, I think there is a bug in your project (that's why I wanted to fork it). In case of POST Method, if you had values in "body" (.withBody("{name:popapp ,age:27}")), this is not working ! The request doesn't have the body params.

    TY

    opened by Aximem 5
Owner
idan ben shimon
idan ben shimon
Flower - Super cool Android library to manage networking and database caching with ease

Flower Super cool Android library to manage networking and database caching with ease. It allows developers to use remote resources on-the-fly OR Comb

Rajesh Hadiya 192 Dec 26, 2022
Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manipulating application data on-the-go.

Pluto Pluto is a on-device debugger for Android applications, which helps in inspection of HTTP requests/responses, capture Crashes and ANRs and manip

Mocklets 8 Aug 22, 2022
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

马天宇 829 Dec 29, 2022
Android Easy Http - Simplest android http request library.

Android Easy Http Library 繁體中文文檔 About Android Easy Http Library Made on OkHttp. Easy to do http request, just make request and listen for the respons

null 13 Sep 30, 2022
Whois4K - A library for who is requests

Whois4K - A library for who is requests

Lyzev 1 Apr 6, 2022
SimpleApiCalls is a type-safe REST client for Android. The library provides the ability to interact with APIs and send network requests with HttpURLConnection.

SimpleApiCalls ?? SimpleApiCalls is a type-safe REST client for Android. The library provides the ability to interact with APIs and send network reque

null 4 Nov 28, 2022
Easily upload files (Multipart/Binary/FTP out of the box) in the background with progress notification. Support for persistent upload requests, customizations and custom plugins.

ℹ️ ?? Get started with 4.x ?? Try it out Get the demo APK Still using 3.x ? It's not maintained or supported. You may have security issues and problem

Alex Gotev 2.7k Jan 3, 2023
A small Android project to practice executing network requests and parsing the network response

InspirationalQuotesExercise A small Android project to practice executing network requests and parsing the network response This app uses the ZenQuote

Caren 0 Oct 13, 2021
HttpMocker is a simple HTTP mocking library written in Kotlin to quickly and easily handle offline modes in your apps

HttpMocker HttpMocker is a very lightweight Kotlin library that allows to mock HTTP calls relying on either OkHttp or the Ktor client libraries. It ca

David Blanc 174 Nov 28, 2022
Monitoring water tanker level using NodeMCU ESP8266 and HC-SR04P Ultrasonic Sensor and broadcasting it using a simple HTTP server inside NodeMCU ESP8266 and show data in an Android App

WaterLevel Preface This project aims to finding a tanker water level using NodeMCU with ESP8266 core and HC-SR04P Ultrasonic sensor and broadcasting i

YaMiN 12 Dec 20, 2022
MVVM with simple HTTP Request Example

Minimum MVVM Koin (Kotlin Dependency Injection) Coroutines View Model Lifecycle News API Retrofit Rx Java Rx Android OkHttp Client Result ScreenShot 1

Faisal Amir 6 Dec 1, 2022
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Jan 8, 2023
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

AMIT SHEKHAR 5.5k Dec 27, 2022
The easiest HTTP networking library for Kotlin/Android

Fuel The easiest HTTP networking library for Kotlin/Android. You are looking at the documentation for 2.x.y.. If you are looking for the documentation

Kittinun Vantasin 4.3k Jan 8, 2023
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

AndroidAsync AndroidAsync is a low level network protocol library. If you are looking for an easy to use, higher level, Android aware, http request li

Koushik Dutta 7.3k Jan 2, 2023
Java HTTP Request Library

Http Request A simple convenience library for using a HttpURLConnection to make requests and access the response. This library is available under the

Kevin Sawicki 3.3k Jan 6, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Jan 5, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Dec 24, 2022