http

a facade of Apache Http Client and OkHttp

License

License

The Apache Software License, Version 2.0
GroupId

GroupId

io.github.hadix-lin
ArtifactId

ArtifactId

http
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

http
a facade of Apache Http Client and OkHttp
Project URL

Project URL

https://github.com/hadix-lin/http
Source Code Management

Source Code Management

https://github.com/hadix-lin/http

Download http

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.hadix-lin/http/ -->
<dependency>
    <groupId>io.github.hadix-lin</groupId>
    <artifactId>http</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.hadix-lin/http/
implementation 'io.github.hadix-lin:http:1.0'
// https://jarcasting.com/artifacts/io.github.hadix-lin/http/
implementation ("io.github.hadix-lin:http:1.0")
'io.github.hadix-lin:http:jar:1.0'
<dependency org="io.github.hadix-lin" name="http" rev="1.0">
  <artifact name="http" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.hadix-lin', module='http', version='1.0')
)
libraryDependencies += "io.github.hadix-lin" % "http" % "1.0"
[io.github.hadix-lin/http "1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.31
org.slf4j : slf4j-api jar 1.7.25
com.fasterxml.jackson.module : jackson-module-kotlin jar 2.9.8

provided (4)

Group / Artifact Type Version
com.squareup.okhttp3 : okhttp jar 3.9.1
com.squareup.okhttp3 : logging-interceptor jar 3.9.1
org.apache.httpcomponents : httpclient jar 4.5.5
org.apache.httpcomponents : httpmime jar 4.5.5

test (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-test-junit jar 1.3.31
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

http

FOSSA Status

链式调用风格的http客户端api抽象.

提供apache httpclient和okhttp两种实现.

模块使用时依赖http包,以及apache httpclient或okhttp即可.

示例:

//普通文本get请求
String resp = Http.req("http://www.baidu.com").submitForText();

//需要增加参数?参数编码会自动进行处理,所以可以直接传递原文参数
String resp 
    = Http.req("http://www.baidu.com")
        .param("key",v)//增加单个参数,可以多次调用
        .params(k1,v1,k2,v2)//一次性增加多个参数,也可以传递map作为参数
        .submitForText();
//返回的响应也会按http响应中的contentType头指定的编码进行解码,如果没有则默认使用utf8解码

//以对象为参数,返回对象
ReqObject reqObject = new ReqObject();
RespObjct respObject 
    = Http.req("http://host:port/path/to/api")
        .method(POST)
        .body(reqObject)
        .submitForObject(RespObject.class);

//也可以使用Http.newBuilder来自行构建http对象,可以配置超时时间和连接池的最大连接数等.
Http http = Http.newBuilder().soTimeout(1000).maxConnTotal(10).build();
http.req("http://www.baidu.com").submitForText();

//如果想进行更多设置可以直接获取具体实现的builder
Http.Builder builder = Http.newBuilder();
// apache client实现
HttpClientBuilder internalBuilder = 
    (HttpClientBuilder) builder.getInternalBuilder();
// okhttp实现
OkHttpClient.Builder internalBuilder =
    (OkHttpClient.Builder) builder.getInternalBuilder();
// 调用内部实现进行自定义设置,无须调用最终的build方法
internalBuilder.setXXX().setXXX()
// 使用Http.Builder的build方法构建实例
Http http = builder.build();

License

FOSSA Status

Versions

Version
1.0