https://github.com/behringer24/serviceclient
Java/Android class for easy web service requests. Response can be plain text or JSON. Uses HttpUrlConnection
https://github.com/behringer24/serviceclient
Last synced: about 1 year ago
JSON representation
Java/Android class for easy web service requests. Response can be plain text or JSON. Uses HttpUrlConnection
- Host: GitHub
- URL: https://github.com/behringer24/serviceclient
- Owner: behringer24
- License: gpl-2.0
- Created: 2013-10-01T18:02:17.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-12-29T23:02:32.000Z (over 8 years ago)
- Last Synced: 2025-01-24T15:41:51.870Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 94.7 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ServiceRequest
A utility Java class developed for Android to handle easy web service requests. The response can be plain text or JSON. For the low level connection HttpUrlConnection is used.
## Features
- easy handling of POST and GET requests
- supports String or JSONObject as response types
- supports Multipart-Form-Data POST for uploading files
## How to include the dependency using JitPack.io
[](https://jitpack.io/#behringer24/ServiceClient)
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```gradle
dependencies {
compile 'com.github.behringer24:ServiceClient:1.1'
}
```
## Example code
String es response
```java
ServiceClient service = new ServiceClient("http://yoursite.com/api/service", RequestMethod.POST);
service.addParameter("name", "Max Mustermann");
service.addParameter("email", "max@mustermann.com");
try {
String response = service.request();
} catch {IOException e} {
// handle connection errors
}
```
JSONObject as response
```java
ServiceClient service = new ServiceClient("http://yoursite.com/api/jsonService", RequestMethod.POST);
service.addParameter("name", "Max Mustermann");
service.addParameter("email", "max@mustermann.com");
try {
JSONObject response = service.requestJson();
} catch {IOException e} {
// handle connection errors
} catch {JSONException e}
// handle JSON parse errors
}
```
Please remember to put network access in AsyncTask to keep it out of the UI-thread