NiceHttp - A small and simple OkHttp wrapper to ease scraping

Overview

NiceHttp

A small and simple OkHttp wrapper to ease scraping. Mostly for personal use.

Featuring:

  • Document scraping using jsoup
  • Json parsing using jackson
  • Easy functions akin to python requests

Getting started

Setup

In app/build.gradle repositories:

maven { url 'https://jitpack.io' }

In app/build.gradle dependencies:

implementation 'com.github.Blatzar:NiceHttp:0.1.3'

Scraping a document

val requests = Requests()
val doc = requests.get("https://github.com/Blatzar/NiceHttp").document
// Using CSS selectors to get the about text
println(doc.select("p.f4.my-3").text())

Parsing json

() println(json.description)">
data class GithubJson(
    val description: String,
    val html_url: String,
    val stargazers_count: Int,
    val private: Boolean
)

val requests = Requests()
val json = requests.get("https://api.github.com/repos/blatzar/nicehttp").parsed<GithubJson>()
println(json.description)

Using cache

(This should work, but I have had issues getting cache hits when testing)

// Just pass in a 
val cache = Cache(
    File(cacheDir, "http_cache"),
    50L * 1024L * 1024L // 50 MiB
)

val okHttpClient = OkHttpClient.Builder()
    .cache(cache)
    .build()

val cacheClient = Requests(okHttpClient)
cacheClient.get("...", cacheTime = 1, cacheUnit = TimeUnit.HOURS)
You might also like...
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

IceNet - Fast, Simple and Easy Networking for Android

IceNet FAST, SIMPLE, EASY This library is an Android networking wrapper consisting of a combination of Volley, OkHttp and Gson. For more information s

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

Uppics - A simple app that authenticates a user and allows them to post images which can then be upvoted or downvoted
Uppics - A simple app that authenticates a user and allows them to post images which can then be upvoted or downvoted

UpPics A simple app that authenticates a user and allows them to post images whi

super simple library to manage http requests.

HttpAgent super simple library to manage http requests. Gradle dependencies { implementation 'com.studioidan.httpagent:httpagent:1.0.16@aar' } No

Very simple SMS to API gateway

sms2api Very simple SMS to API gateway for Android devices. It's NOT Google Play compatible, due to the security restrictions but it works well on you

Simple kafka client for monitoring topic events. Client has UI powered by Darklaf
Simple kafka client for monitoring topic events. Client has UI powered by Darklaf

kafka-client Simple kafka client for monitoring topic values. How to start $ java -jar kafka-client-1.0.jar How to use specify kafka hosts in config.y

Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin
Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin

Kotlin REST Retrofit Sencillo cliente para consumir una API REST con Retrofit us

MVVM with simple HTTP Request Example
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

Comments
  • Crashing on API <26

    Crashing on API <26

    I saw the comment but still something must be wrong there, its still crashing on API <26

    java.lang.NoSuchMethodError: No virtual method getParameterCount()I in class Ljava/lang/reflect/Method; or its super classes (declaration of 'java.lang.reflect.Method' appears in /system/framework/core-oj.jar)
            at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._isIncludableMemberMethod(AnnotatedMethodCollector.java:187)
            at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:118)
            at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:49)
            at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:40)
            at com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:387)
            at com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:327)
            at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:680)
            at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:422)
            at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getPropertyMap(POJOPropertiesCollector.java:386)
            at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getProperties(POJOPropertiesCollector.java:233)
            at com.fasterxml.jackson.databind.introspect.BasicBeanDescription._properties(BasicBeanDescription.java:164)
            at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findProperties(BasicBeanDescription.java:239)
            at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._findCreatorsFromProperties(BasicDeserializerFactory.java:328)
            at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:272)
            at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:223)
            at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:261)
            at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:150)
            at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:415)
            at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:350)
            at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
            at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
            at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
            at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:642)
            at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4805)
            at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4675)
            at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3629)
            at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3612)
    

    Not sure if this is an issue on the fasterxml side

    opened by Nanoc6 3
  • `OkHttpClient` no longer implements Cloneable

    `OkHttpClient` no longer implements Cloneable

    Since version 5.0.0-alpha.7 OkHttpClient no longer implements Cloneable.

    This library uses version 5.0.0-alpha.9 of okhttp and needs to remove passing the OkHttpClient class as baseClient in Requests.


    image

    opened by scrazzz 1
  • Add Async-ed Requests Functionality

    Add Async-ed Requests Functionality

    Library

    • Added kotlinx.coroutine dependency
    • Add Async Functionality to Call
    • Updated target version to 32

    Example App

    • Added androidx.lifecycle dependency
    • Add comments to examples
    • Add Async Example

    Misc

    • added .idea folder to gitignore
    opened by brahmkshatriya 0
Releases(0.4.2)
Owner
LagradOst
App developer Lag#5744
LagradOst
Mock your datas for Okhttp and Retrofit in json format in just a few moves

okhttp-json-mock This simple library helps you mock your data for using with okhttp+retrofit in json format in just a few moves. it forwards the reque

Mad Mirrajabi 240 Nov 25, 2022
A basic list application designed using MVVM pattern with Retrofit, OkHttp, and Hilt for dependency injection

FRExercise A basic list application designed using MVVM pattern with Retrofit, O

null 0 Dec 22, 2021
SimpleInterceptor for okhttp

SimpleInterceptor Simpleinceptor is the interception interface tool of Android okhttp client, which is convenient for testing or development and quick

zhonghua 25 Jun 21, 2022
Customizable OkHttp Logging Interceptor

An OkHttp interceptor which logs HTTP request and response data and allows output customization.

Bartek Wesołowski 22 Aug 13, 2022
A "fluent" OkHTTP library for Kotlin based on string extensions.

okfluent A "fluent" OkHTTP library for Kotlin based on string extensions. Do not take this project seriously, I just wanted to show that this kind of

Duale Siad 0 Nov 23, 2021
A Beautiful Log Printer For OkHttp.

LogDog A Beautiful Log Printer For OkHttp. It looks like this: Import repositories { maven { url 'https://jitpack.io' } } //something else... impl

Michael Lee 3 Jun 21, 2022
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
Multiplatform coroutine-based HTTP client wrapper for Kotlin

networkinkt This is a lightweight HTTP client for Kotlin. It relies on coroutines on both JS & JVM platforms. Here is a simple GET request: val text =

Egor Zhdan 31 Jul 27, 2022
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
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