hero

OkHttps V2

A lightweight and powerful HTTP client on top of OkHttp

Get Started →

Lightweight Elegant Easy

OkHttps is very lightweight, less than half the size of Retrofit, and does not depend on a specific platform. The API semantics are simple and comfortable.

Out of the box features

Asynchronous preprocessor, callback executor, global listener, callback prevent mechanism, file upload and download, process control, progress monitoring.

More practical features

URL placeholder, lambda callback, JSON auto encapsulation parsing, okhttp features like interceptor, connection pool, cookiejar, etc.

#
As Elegant as Art, As Easy as 1, 2, 3

HTTP http = HTTP.builder()
        .baseUrl("http://api.example.com")
        .addMsgConvertor(new GsonMsgConvertor());
        .build();

// Synchronous HTTP
List<User> users = http.sync("/users") 
        .get()                          // GET method
        .getBody()                      // response body
        .toList(User.class);            // Automatic deserialization

// Asynchronous HTTP
http.async("/users/1")
        .setOnResponse((HttpResult res) -> {
            // Automatic deserialization
            User user = res.getBody().toBean(User.class);
        })
        .get();                         // GET method

// WebSocket
http.webSocket("/chat") 
        .setOnMessage((WebSocket ws, Message msg) -> {
            // Automatic deserialization
            Chat chat = msg.toBean(Chat.class);
            // Automatic Serialization
            ws.send(chat); 
        })
        .listen();                     // Start listening
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Lean More