{"id":17081011,"url":"https://github.com/blatzar/nicehttp","last_synced_at":"2025-04-12T21:09:08.056Z","repository":{"id":41866344,"uuid":"471538819","full_name":"Blatzar/NiceHttp","owner":"Blatzar","description":"A small and simple OkHttp wrapper to ease scraping. Mostly for personal use.","archived":false,"fork":false,"pushed_at":"2025-03-28T00:40:01.000Z","size":181,"stargazers_count":36,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T21:09:01.126Z","etag":null,"topics":["android","kotlin-android","library","okhttp"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blatzar.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2022-03-18T22:56:44.000Z","updated_at":"2025-03-28T00:38:51.000Z","dependencies_parsed_at":"2023-10-12T01:09:09.776Z","dependency_job_id":null,"html_url":"https://github.com/Blatzar/NiceHttp","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blatzar%2FNiceHttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blatzar%2FNiceHttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blatzar%2FNiceHttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blatzar%2FNiceHttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blatzar","download_url":"https://codeload.github.com/Blatzar/NiceHttp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631676,"owners_count":21136562,"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","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","kotlin-android","library","okhttp"],"created_at":"2024-10-14T12:49:10.365Z","updated_at":"2025-04-12T21:09:08.038Z","avatar_url":"https://github.com/Blatzar.png","language":"Kotlin","readme":"# NiceHttp\n\n[![](https://jitpack.io/v/Blatzar/NiceHttp.svg)](https://jitpack.io/#Blatzar/NiceHttp)\n\nA small and simple Android OkHttp wrapper to ease scraping. Mostly for personal use.\n\nFeaturing:\n\n- Document scraping using jsoup\n- Json parsing using jackson\n- Easy functions akin to python requests\n\n## Getting started\n\n### Setup\n\nIn build.gradle repositories:\n\n```groovy\nmaven { url 'https://jitpack.io' }\n```\n\nIn app/build.gradle dependencies:\n\n```groovy\nimplementation 'com.github.Blatzar:NiceHttp:+'\n```\n\n### Scraping a document\n\n```kotlin\nlifecycleScope.launch {\n    val requests = Requests()\n    val doc = requests.get(\"https://github.com/Blatzar/NiceHttp\").document\n    // Using CSS selectors to get the about text\n    println(doc.select(\"p.f4.my-3\").text())\n}\n```\n\n### Parsing json\n\n```kotlin\ndata class GithubJson(\n    val description: String,\n    val html_url: String,\n    val stargazers_count: Int,\n    val private: Boolean\n)\n\n// Implement your own requests parser here with your library of choice, this is with jackson :)\n\nval parser = object : ResponseParser {\n    val mapper: ObjectMapper = jacksonObjectMapper().configure(\n        DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,\n        false\n    )\n\n    override fun \u003cT : Any\u003e parse(text: String, kClass: KClass\u003cT\u003e): T {\n        return mapper.readValue(text, kClass.java)\n    }\n\n    override fun \u003cT : Any\u003e parseSafe(text: String, kClass: KClass\u003cT\u003e): T? {\n        return try {\n            mapper.readValue(text, kClass.java)\n        } catch (e: Exception) {\n            null\n        }\n    }\n\n    override fun writeValueAsString(obj: Any): String {\n        return mapper.writeValueAsString(obj)\n    }\n}\n\nval requests = Requests(responseParser = parser)\nlifecycleScope.launch {\n    val json = requests.get(\"https://api.github.com/repos/blatzar/nicehttp\").parsed\u003cGithubJson\u003e()\n    println(json.description)\n}\n```\n\n### Using cache\n\nNote: For a request to be cached you need to consume the body! You do this by calling .text or .document\n\n```kotlin\n// Just pass in a \nval cache = Cache(\n    File(cacheDir, \"http_cache\"),\n    50L * 1024L * 1024L // 50 MiB\n)\n\nval okHttpClient = OkHttpClient.Builder()\n    .cache(cache)\n    .build()\n\nval cacheClient = Requests(okHttpClient)\nlifecycleScope.launch {\n    // Cache time refers to how long the response could have been cached for \n    cacheClient.get(\"...\", cacheTime = 1, cacheUnit = TimeUnit.HOURS)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblatzar%2Fnicehttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblatzar%2Fnicehttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblatzar%2Fnicehttp/lists"}