Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.9 KB

README.md

File metadata and controls

59 lines (46 loc) · 1.9 KB

Lightweight Asynchronous HTTP Client (LAHC)

Maven metadata URL

This is a very simple and lightweight HTTP client for Java 8+. For bigger projects, use other HTTP client libraries like Apache's HTTPComponents Client or OkHttp.

Adding Lahc as a dependency

Lahc is published on my own repository, located at https://m2.tecc.me/snapshots. It should be named me.tecc.lahc:lahc:[version] (replace [version] with the version you want to use).

Quickies:

  • Gradle:
    repositories {
        maven {
            name 'tecc.me snapshots'
            url 'https://m2.tecc.me/snapshots'
        }
    } 
    dependencies {
        implementation 'me.tecc.lahc:lahc:[version]'
    }

Usage

Note: Usage is subject to change.

Simple request

// Create an HttpClient with its default settings
HttpClient client = new HttpClient();

// Create a request
HttpRequest request = new HttpRequest()
        // the index.html of example.com - you need to be explicit because Lahc doesn't automatically do this 
        .url("https://example.com/index.html");

// Execute the request using the client
Promise<HttpResponse> responseFuture = client.execute(request);
// Note that getting the result can throw exceptions - handle them however you want!
try {
    HttpResponse response = responseFuture.get();
    // Lahc creates toString() methods for debugging purposes
    // Very neat! - tecc
    System.out.println("Response: \n" + response)
} catch (Exception e) {
    // Example exception handling - once again, handle how you want
    e.printStackTrace();
}

Licence

Lahc is licensed under the MIT licence. The licence text is available in the LICENSE.txt file.