All Projects → Incendo → HTTP4J

Incendo / HTTP4J

Licence: MIT license
Simple & Lightweight Java 8 HTTP Client

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to HTTP4J

Rump
REST client for Java that allows for easy configuration and default values. Allows for quick request construction and a huge range of modifications by using response/request interceptors, adjusting default values related to HTTP requests and creating custom instances for when you need multiple API connection setups.
Stars: ✭ 55 (+37.5%)
Mutual labels:  http-client, java-http-client
angular6-httpclient-example
Angular 6 HttpClient: Consume RESTful API Example
Stars: ✭ 38 (-5%)
Mutual labels:  http-client
htest
htest is a http-test package
Stars: ✭ 24 (-40%)
Mutual labels:  http-client
roi
A dependency-free http module client.
Stars: ✭ 12 (-70%)
Mutual labels:  http-client
dynamic-cli
A Modern, user-friendly command-line HTTP client for the API testing, and if you're stuck - Search and browse StackOverflow without leaving the CLI
Stars: ✭ 151 (+277.5%)
Mutual labels:  http-client
SimpleNetworking
Scalable and composable API Clients using Swift Combine
Stars: ✭ 48 (+20%)
Mutual labels:  http-client
unity-simple-http
A dead simple HTTP client for Unity3D
Stars: ✭ 32 (-20%)
Mutual labels:  http-client
NClient
💫 NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Stars: ✭ 25 (-37.5%)
Mutual labels:  http-client
jetty-reactive-httpclient
Jetty ReactiveStreams HttpClient
Stars: ✭ 63 (+57.5%)
Mutual labels:  http-client
php-curl-cookbook
PHP CURL Cookbook 📖
Stars: ✭ 83 (+107.5%)
Mutual labels:  http-client
sttp-openapi-generator
Generate sttp client from openapi specification with ease!
Stars: ✭ 26 (-35%)
Mutual labels:  http-client
http
A janet http client library
Stars: ✭ 22 (-45%)
Mutual labels:  http-client
1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (+20%)
Mutual labels:  http-client
reky
Reky is an opensource API development platform. It automatically visualizes API response with outstanding graphs & tables.
Stars: ✭ 22 (-45%)
Mutual labels:  http-client
resto
🔗 a CLI app can send pretty HTTP & API requests with TUI
Stars: ✭ 113 (+182.5%)
Mutual labels:  http-client
jetty-load-generator
jetty-project.github.io/jetty-load-generator/
Stars: ✭ 62 (+55%)
Mutual labels:  http-client
go-http-client
An enhanced http client for Golang
Stars: ✭ 48 (+20%)
Mutual labels:  http-client
Proxy
The type-safe REST library for .NET Standard 2.0 (NetCoreStack Flying Proxy)
Stars: ✭ 40 (+0%)
Mutual labels:  http-client
http
Tiny, embeddable HTTP client with simple API for the browser
Stars: ✭ 21 (-47.5%)
Mutual labels:  http-client
rawhttp
HTTP library to make it easy to deal with raw HTTP.
Stars: ✭ 156 (+290%)
Mutual labels:  http-client

HTT4J

Description

This is a simple, lightweight and tiny wrapper for Java's HttpURLConnection. It has no external dependencies and is written for Java 8.

It comes with a entity mapping system (serialization and deserialization for request and response bodies) with optional mappings for third party libraries (currently supporting: GSON).

Rationale

Most HTTP client for Java are either built for Java 11+, or have a large amount of dependencies, which means that in order to use them, one needs to built a fatjar that often end up being huge. This aims to offer a nicer way to interact with the Java 8 HTTP client, without having to double the size of the output artifacts.

Usage

Repository

Releases are published to the central repository, snapshots are published to S01 OSS Sonatype.

repositories {
    mavenCentral()
}

dependencies {
    compileOnly("com.intellectualsites.http:HTTP4J:1.3")
}
<dependency>
    <groupId>com.intellectualsites.http</groupId>
    <artifactId>HTTP4J</artifactId>
    <version>1.3</version>
</dependency>

Code

JavaDocs: https://javadoc.io/doc/com.intellectualsites.http4j/HTTP4J

All requests are done using an instance of com.intellectualsites.http.HttpClient:

HttpClient client = HttpClient.newBuilder()
    .withBaseURL("https://your.api.com")
    .build();

The client also take in a com.intellectualsites.http.EntityMapper instance. This is used to map request & response bodies to Java objects. By default, it includes a mapper for Java strings.

EntityMapper entityMapper = EntityMapper.newInstance()
    .registerDeserializer(JsonObject.class, GsonMapper.deserializer(JsonObject.class, GSON));

The above snippet would create an entity mapper that maps to and from Java strings, and from HTTP response's to GSON json objects.

This can then be included in the HTTP client by using <builder>.withEntityMapper(mapper) to be used in all requests, or added to individual requests.

HTTP4J also supports request decorators, that can be used to modify each request. These are added by using:

builder.withDecorator(request -> {
    request.doSomething();
});

The built client can then be used to make HTTP requests, like such:

client.post("/some/api").withInput(() -> "Hello World")
    .onStatus(200, response -> {
        System.out.println("Everything is fine");
        System.out.println("Response: " + response.getResponseEntity(String.class));
    })
    .onStatus(404, response -> System.err.println("Could not find the resource =("))
    .onRemaining(response -> System.err.printf("Got status code: %d\n", response.getStatusCode()))
    .onException(Throwable::printStackTrace)
    .execute();

Exception Handling

HTTP4J will forward all RuntimeExceptions by default, and wrap all other exceptions (that do not extend RuntimeException) in a RuntimeException.

By using onException(exception -> {}) you are able to modify the behaviour.

Examples

More examples can be found in HttpClientTest.java

Projects using HTTP4J:

IntellectualSites/Arkitektonika-Client: Client for the Arkitektonika API broccolai/tickets: Discord bot

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].