{"id":19419595,"url":"https://github.com/intellectualsites/http4j","last_synced_at":"2025-04-24T14:31:52.423Z","repository":{"id":38314853,"uuid":"276424304","full_name":"IntellectualSites/HTTP4J","owner":"IntellectualSites","description":"Simple \u0026 Lightweight Java 8 HTTP Client","archived":false,"fork":false,"pushed_at":"2025-04-01T02:22:35.000Z","size":453,"stargazers_count":49,"open_issues_count":2,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-21T15:24:26.356Z","etag":null,"topics":["http-client","java","java-8","java-http-client","java-http-request","java-rest"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IntellectualSites.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":["IntellectualSites"]}},"created_at":"2020-07-01T16:09:56.000Z","updated_at":"2025-04-09T18:50:57.000Z","dependencies_parsed_at":"2023-12-24T00:30:54.334Z","dependency_job_id":"b51a65df-e6bf-4f81-86de-4fb8075fc50b","html_url":"https://github.com/IntellectualSites/HTTP4J","commit_stats":{"total_commits":78,"total_committers":4,"mean_commits":19.5,"dds":0.5256410256410257,"last_synced_commit":"35bfe709340b4822a622b2d3289ba3cc061887b1"},"previous_names":["incendo/http4j"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntellectualSites%2FHTTP4J","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntellectualSites%2FHTTP4J/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntellectualSites%2FHTTP4J/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntellectualSites%2FHTTP4J/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IntellectualSites","download_url":"https://codeload.github.com/IntellectualSites/HTTP4J/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250643453,"owners_count":21464177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-client","java","java-8","java-http-client","java-http-request","java-rest"],"created_at":"2024-11-10T13:18:21.376Z","updated_at":"2025-04-24T14:31:52.412Z","avatar_url":"https://github.com/IntellectualSites.png","language":"Java","readme":"# HTT4J\n\n## Description\n\nThis is a simple, lightweight and tiny wrapper for Java's HttpURLConnection. It has no external\ndependencies and is written for Java 8.\n\nIt comes with a entity mapping system (serialization and deserialization for request and response bodies)\nwith optional mappings for third party libraries (currently supporting: GSON).\n\n### Rationale\n\nMost HTTP client for Java are either built for Java 11+, or have a large amount of dependencies,\nwhich means that in order to use them, one needs to built a fatjar that often end up being huge.\nThis aims to offer a nicer way to interact with the Java 8 HTTP client, without having to double the\nsize of the output artifacts.\n\n## Usage\n\n### Repository\n\nReleases are published to the central repository, snapshots are published to S01 OSS Sonatype.\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"com.intellectualsites.http:HTTP4J:VERSION)\n}\n```\n\nEnsure to relocate HTTP4J using the gradle shadow plugin to your classpath.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.intellectualsites.http\u003c/groupId\u003e\n    \u003cartifactId\u003eHTTP4J\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Code\n\n**JavaDocs:** [https://javadoc.io/doc/com.intellectualsites.http/HTTP4J](https://javadoc.io/doc/com.intellectualsites.http/HTTP4J)\n\nAll requests are done using an instance of `com.intellectualsites.http.HttpClient`:\n\n```java\nHttpClient client = HttpClient.newBuilder()\n    .withBaseURL(\"https://your.api.com\")\n    .build();\n```\n\nThe client also take in a `com.intellectualsites.http.EntityMapper` instance. This\nis used to map request \u0026 response bodies to Java objects. By default, it includes a mapper\nfor Java strings.\n\n```java\nEntityMapper entityMapper = EntityMapper.newInstance()\n    .registerDeserializer(JsonObject.class, GsonMapper.deserializer(JsonObject.class, GSON));\n```\n\nThe above snippet would create an entity mapper that maps to and from Java strings, and\nfrom HTTP response's to GSON json objects.\n\nThis can then be included in the HTTP client by using `\u003cbuilder\u003e.withEntityMapper(mapper)` to\nbe used in all requests, or added to individual requests.\n\nHTTP4J also supports request decorators, that can be used to modify each request. These are\nadded by using:\n\n```java\nbuilder.withDecorator(request -\u003e {\n    request.doSomething();\n});\n```\n\nThe built client can then be used to make HTTP requests, like such:\n\n```java\nclient.post(\"/some/api\").withInput(() -\u003e \"Hello World\")\n    .onStatus(200, response -\u003e {\n        System.out.println(\"Everything is fine\");\n        System.out.println(\"Response: \" + response.getResponseEntity(String.class));\n    })\n    .onStatus(404, response -\u003e System.err.println(\"Could not find the resource =(\"))\n    .onRemaining(response -\u003e System.err.printf(\"Got status code: %d\\n\", response.getStatusCode()))\n    .onException(Throwable::printStackTrace)\n    .execute();\n```\n\n#### Exception Handling\n\nHTTP4J will forward all RuntimeExceptions by default, and wrap all other exceptions (that do not\nextend RuntimeException) in a RuntimeException.\n\nBy using `onException(exception -\u003e {})` you are able to modify the behaviour.\n\n#### Examples\n\nMore examples can be found in [HttpClientTest.java](https://github.com/IntellectualSites/HTTP4J/blob/main/src/test/java/com/intellectualsites/http/HttpClientTest.java)\n\n## Projects using HTTP4J:\n\n**[IntellectualSites/Arkitektonika-Client](https://github.com/IntellectualSites/Arkitektonika-Client)**: Client for the Arkitektonika API\n**[broccolai/tickets](https://github.com/broccolai/tickets)**: Discord bot\n","funding_links":["https://github.com/sponsors/IntellectualSites"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintellectualsites%2Fhttp4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintellectualsites%2Fhttp4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintellectualsites%2Fhttp4j/lists"}