https://github.com/kshitij86/offred-android
Make simple API requests from your apps, easily.
https://github.com/kshitij86/offred-android
android android-library api-client java
Last synced: 3 months ago
JSON representation
Make simple API requests from your apps, easily.
- Host: GitHub
- URL: https://github.com/kshitij86/offred-android
- Owner: kshitij86
- Created: 2020-06-11T13:09:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-18T14:31:33.000Z (almost 6 years ago)
- Last Synced: 2025-06-11T19:39:21.780Z (about 1 year ago)
- Topics: android, android-library, api-client, java
- Language: Java
- Homepage:
- Size: 252 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Offred
#### Offred eliminates the need to construct complicated classes for simple API requests for your apps.
# Add dependency
1. Add it in your root build.gradle at the end of repositories:
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
2. Add the dependency
```
dependencies {
implementation 'com.github.kshitij86:offred-android:'
}
```
The example application shows usages in an actual app environment.
# Usage
### _GET_ requests
Offred.get(url)
API calls are made on a separate background thread and a Response object is returned.
```
try{
Offred offred = new Offred();
Future fr = offred.get("https://jsonplaceholder.typicode.com/todos/1");
Response data = fr.get();
if(!data.isException && data.resBody != "NULL_REQUEST"){
Log.d(TAG, "onClick: Call to web service successful");
}
} catch (Exception e){
Log.e(TAG, e.getMessage());
}
```
### _POST_ requests
Offred.post(url, postData)
```
try{
...
// JSON to POST to RESTful API
String passJSON = "{\"name\":" + name.getText() + ",\"salary\":" + salary.getText() + ",\"age\":"+ age.getText() +"}";
Offred offred = new Offred();
Future fr = offred.post("https://dummy.restapiexample.com/api/v1/create", passJSON);
Response data = fr.get();
...
} catch (Exception e){
Log.e(TAG, e.getMessage());
}
```
### _DELETE_ requests
Offred.delete(url)
### `RESPONSE` object
Performing a HTTP request returns a `Response` object, which contains response body along with response headers, total request time etc.
Below is a full list.
| ```Response data```|```Type```|
|---------------|-------------|
| ```time``` | ```double``` |
| ```resBody```| ```JSONObject```|
| ```statusCode```| ```int``` |
| ```headers``` | ```Map>``` |
| ```isException``` | ```Boolean``` |
# Future Scope & TODOs
1. Better `Exception` handling
2. Extend HTTP requests
3. Caching support
4. Support for XML data
# Demo App
The app included with repo showcases use cases for Offred.
[Demo app](ss.jpeg)