{"id":32642872,"url":"https://github.com/smith8h/sconnect","last_synced_at":"2025-10-31T03:06:49.484Z","repository":{"id":63148109,"uuid":"565248097","full_name":"smith8h/SConnect","owner":"smith8h","description":"A Http client based library that use OkHttp3 for simply making requests to URLs and APIs, and get a response as Json or plain text.","archived":false,"fork":false,"pushed_at":"2025-03-03T17:26:48.000Z","size":365,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T18:34:38.594Z","etag":null,"topics":["android","android-lib","android-library","connect","http","http-client","http-request","http-requests","http-response","https","java","json","json-parser","kotlin","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smith8h.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-12T19:49:21.000Z","updated_at":"2025-03-03T17:26:51.000Z","dependencies_parsed_at":"2022-11-13T22:31:48.831Z","dependency_job_id":"4566866b-6c68-4f3c-bc10-429702a20d12","html_url":"https://github.com/smith8h/SConnect","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/smith8h/SConnect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smith8h%2FSConnect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smith8h%2FSConnect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smith8h%2FSConnect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smith8h%2FSConnect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smith8h","download_url":"https://codeload.github.com/smith8h/SConnect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smith8h%2FSConnect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281920264,"owners_count":26583990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-31T02:00:07.401Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-lib","android-library","connect","http","http-client","http-request","http-requests","http-response","https","java","json","json-parser","kotlin","rest-api"],"created_at":"2025-10-31T03:03:57.972Z","updated_at":"2025-10-31T03:06:49.472Z","avatar_url":"https://github.com/smith8h.png","language":"Java","readme":"# SConnect\r\n\r\n![Builds and tests](https://github.com/smith8h/SConnect/actions/workflows/build.yml/badge.svg)\r\n[![JitPack release](https://jitpack.io/v/smith8h/SConnect.svg)](https://jitpack.io/#smith8h/SConnect)\r\n![Latest release](https://img.shields.io/github/v/release/smith8h/SConnect?include_prereleases\u0026amp;label=latest%20release)\r\n![stable version](https://img.shields.io/badge/stable_version-v6.0-blue)\r\n![stability-stable](https://img.shields.io/badge/stability-stable-green.svg)\r\n![minimumSDK](https://img.shields.io/badge/minSDK-24-f39f37)\r\n![Repository size](https://img.shields.io/github/repo-size/smith8h/SConnect)\r\n\r\n\u003c/br\u003e\r\n\r\n**(SConnect)** A Http client based library that use *OkHttp3* for simply making requests to URLs and APIs, and get a response as Json or plain text.\r\n\r\n\u003c/br\u003e\r\n\r\n## Content\r\n\r\n- [**Setup**](#setup)\r\n- [**Changelog**](https://github.com/smith8h/SConnect/blob/main/CHANGELOG.md)\r\n- [**Documentation**](#documentation)\r\n- [**Example Code**](#example-code)\r\n- [**Donations :heart:**](#donations)\r\n\r\n\u003c/br\u003e\r\n\r\n## Setup\r\n\r\n\u003e **Step 1.**\r\n\u003e Add the JitPack repository to your build file.\u003c/br\u003e\r\n\u003e Add it in your root build.gradle at the end of repositories:\r\n\r\n```gradle\r\nallprojects {\r\n    repositories {\r\n        ...\r\n        maven { url 'https://jitpack.io' }\r\n        ...\r\n    }\r\n}\r\n```\r\n\r\n\u003e **Step 2.** Add the dependency:\r\n\r\n```gradle\r\ndependencies {\r\n    ...\r\n    implementation 'com.github.smith8h:SConnect:v5.0'\r\n    ...\r\n}\r\n```\r\n\r\n\u003e [!WARNING]\r\n\u003e Add these dependencies in case you facing some compile or runtime errors:\r\n\r\n```gradle\r\ndependencies {\r\n    ...\r\n    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'\r\n    implementation 'com.squareup.okio:okio:3.5.0'\r\n    implementation 'com.google.code.gson:gson:2.10.1'\r\n    ...\r\n}\r\n```\r\n\r\n\u003c/br\u003e\r\n\r\n## Documentation\r\n\r\nTo create a connection first pass a context using `with()` method:\r\n\r\n```java\r\n    SConnect.with(context)\r\n```\r\n\r\nThen pass the callback interface to deal with the response using `callback()` method:\r\n\r\n```java\r\n    SConnect.with(context).callback(new SConnectCallBack() {\r\n        @Override\r\n        public void onFailure(SResponse response, String tag) {}\r\n            \r\n        @Override\r\n        public void onSuccess(SResponse response, String tag, Map\u003cString, Object\u003e responseHeaders) {\r\n            // use response, tag, responseHeaders\r\n            if (response.isJSON() \u0026\u0026 response.isMap()) {\r\n                Toast.makeText(context, response.getMap().getString(\"key\"), Toast.LENGTH_SHORT).show();\r\n            } else {\r\n                Toast.makeText(context, response.toString(), Toast.LENGTH_SHORT).show();\r\n            }\r\n        }\r\n    })\r\n```\r\n\r\nAfter that, if you need to add headers, params to your connection. add them using methods:\r\n\r\n```java\r\n    .addHeaders(Map\u003cString, Object\u003e)\r\n    .addHeader(\"key\", value) // you can also use add header one by one.\r\n\r\n\r\n    .addParams(Map\u003cString, Object\u003e)\r\n    .addParam(\"key\", value) // you can  also use add header one by one.\r\n        \r\n    // and then set the param type.\r\n    .paramsType(SConnect.PARAM) // or BODY\r\n\r\n\r\n    // if required for some connections\r\n    .mediaType(\"a string represent the media type applied to a connection\")\r\n```\r\n\r\nthen pass the url using `url()` method:\r\n\r\n```java\r\n    .url(\"url\")\r\n```\r\n\r\n**Optional method |** use `tag()` to set a tag to every connection (useful when you do a multiple connections at same time and need to recognize them).\r\n\r\n```java\r\n    .tag(\"someTag\")\r\n```\r\n\r\nfinaly, use any of `get()`, `post()`, `put()`, `delete()`, `patch()`, `options()` or `head()` methods corresponding to your connection:\r\n\r\n```java\r\n    .get()\r\n    // or: post() | put() | delete() | patch() | options() | head()\r\n```\r\n\r\n## Example Code\r\n\r\n• connections doesn't need params/headers:\r\n\r\n```java\r\n    SConnect.with(this)\r\n            .callback(callback)\r\n            .url(url)\r\n            .get(); // post | put | delete\r\n            // also pass tag if you need to recognize multiple requesrs which one is giving response\r\n```\r\n\r\n• connections need params/headers:\r\n\r\n```java\r\n\r\n    Map\u003cString, Object\u003e params = new HashMap\u003c\u003e();\r\n    params.put(\"key\", value);\r\n    ...\r\n    Map\u003cString, Object\u003e headers = new HashMap\u003c\u003e();\r\n    params.put(\"key\", value);\r\n    ...\r\n            \r\n    SConnect.with(this)\r\n            .callback(callback)\r\n            .addParams(params)\r\n            .paramsType(SConnect.PARAM) // or BODY\r\n            .addHeaders(headers)\r\n            .mediaType(\"json/application;Charset:UTF-8\")\r\n            .url(\"http://example.url.com\")\r\n            .tag(\"sample\")\r\n            .get(); // post | put | delete...\r\n```\r\n\r\n\u003c/br\u003e\r\n\r\nDealing with **Json response* using `SResponse` class\r\n\u003e if response is plain/text or HTML (when requesting websites) simply use `response.toString()` method.\r\n\r\n```java\r\n    // get/check response as json (if get a api json response)\r\n    boolean isJSON = response.isJSON();\r\n    // check if response json is Map Object\r\n    boolean isMap = response.isMap();\r\n    // else if it's Array\r\n    boolean isArray = response.isArray();\r\n    \r\n    \r\n    // getting response if it is plain text or json in general\r\n    String text = response.toString();\r\n    \r\n    \r\n    // get response as map object\r\n    SResponse.Map object = response.getMap();\r\n    // now you can access all values in that object using\r\n    // return Object of any value\r\n    Object o = object.get(\"key\");\r\n    // return int\r\n    int i = object.getInt(\"key\");\r\n    // return String\r\n    String s = object.getString(\"key\");\r\n    // return float\r\n    float f = object.getFloat(\"key\");\r\n    // return boolean\r\n    boolean b = object.getBoolean(\"key\");\r\n    // return Map object as above ↑\r\n    // if map object nested inside another map object\r\n    SResponse.Map = object.getMap(\"key\");\r\n    // get keys\r\n    Set\u003cString\u003e keys = object.keys();\r\n    // get values\r\n    List\u003cObject\u003e values = object.values();\r\n    // has key?\r\n    boolean hasKey = object.hasKey(\"key\");\r\n    // has value? (accepts anything)\r\n    boolean hasValue = object.hasValue(Object);\r\n    // iterate through keys \u0026 values\r\n    object.forEach((key, value) -\u003e {\r\n        // use key || value\r\n    });\r\n    // size\r\n    int size = object.size();\r\n    // is empty?\r\n    boolean isEmpty = object.isEmpty();\r\n    // to json string\r\n    String json = object.toString();\r\n    // to HashMap\r\n    HashMap\u003cString, Object\u003e map = object.toMap();\r\n    \r\n    \r\n    // the same but for arrays\r\n    // get response as array from response or from map object\r\n    // this if the response body is array\r\n    SResponse.Array array = response.getArray();\r\n    // and this if response body is object ↑ has an array as value inside it\r\n    SResponse.Array array = object.getArray(\"key\");\r\n    // array class has same methods like map class\r\n    // get at index as object of any value\r\n    Object o = array.get(0);\r\n    // get string \r\n    String s = array.getString(0);\r\n    // get int\r\n    int i = array.getInt(0);\r\n    // get float\r\n    float f = array.getFloat(0);\r\n    // get boolean\r\n    boolean b = array.getBoolean(0);\r\n    // get Map object like above if map object nested inside list\r\n    SResponse.Map m = array.getMap(0);\r\n    // same if it has array inside array\r\n    SResponse.Array a = array.getArray(0);\r\n    // contains something?\r\n    boolean contains = array.contains(Object);\r\n    // iterate through items\r\n    array.forEach(item -\u003e {\r\n        // use item\r\n    });\r\n    // size\r\n    int size = array.size();\r\n    // is empty\r\n    boolean isEmpty = array.isEmpty();\r\n    // to json string\r\n    String json = array.toString();\r\n    // to List\r\n    List\u003cObject\u003e list = array.toList();\r\n    \r\n```\r\n\r\n\u003c/br\u003e\r\n\r\n## Contributors\r\n\r\n\u003ca href=\"https://github.com/smith8h\"\u003e\r\n  \u003cimg src=\"https://contrib.rocks/image?repo=smith8h/smith8h\" /\u003e\r\n\u003c/a\u003e\r\n\u003ca href=\"https://github.com/1on7\"\u003e\r\n  \u003cimg src=\"https://contrib.rocks/image?repo=1on7/pubgh\" /\u003e\r\n\u003c/a\u003e\r\n\r\n\u003cbr/\u003e\r\n\r\n## Donations\r\n\r\n\u003e If you would like to support this project's further development, the creator of this projects or the continuous maintenance of the project **feel free to donate**.\r\nYour donation is highly appreciated. Thank you!\r\n\r\n\u003c/br\u003e\r\n\r\nYou can **choose what you want to donate**, all donations are awesome!\u003c/br\u003e\r\n\r\n\u003c/br\u003e\r\n\r\n[![PayPal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge\u0026logo=paypal\u0026logoColor=white)](https://www.paypal.me/husseinshakir)\r\n[![Buy me a coffee](https://img.shields.io/badge/Buy_Me_A_Coffee-FFDD00?style=for-the-badge\u0026logo=buy-me-a-coffee\u0026logoColor=black)](https://www.buymeacoffee.com/HusseinShakir)\r\n[![Ko-fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge\u0026logo=ko-fi\u0026logoColor=white)](https://ko-fi.com/husseinsmith)\r\n\r\n\u003c/br\u003e\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://raw.githubusercontent.com/smith8h/smith8h/main/20221103_150053.png\" style=\"width: 38%;\"/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cb\u003e\r\n    With :heart:\r\n  \u003c/b\u003e\r\n\u003c/p\u003e\r\n\u003c/br\u003e\r\n","funding_links":["https://www.paypal.me/husseinshakir","https://www.buymeacoffee.com/HusseinShakir","https://ko-fi.com/husseinsmith"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmith8h%2Fsconnect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmith8h%2Fsconnect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmith8h%2Fsconnect/lists"}