{"id":18294822,"url":"https://github.com/joshgontijo/rest-client","last_synced_at":"2026-03-13T15:38:03.725Z","repository":{"id":22567385,"uuid":"91128731","full_name":"joshgontijo/rest-client","owner":"joshgontijo","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-20T20:50:38.000Z","size":760,"stargazers_count":21,"open_issues_count":52,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-08T04:33:28.553Z","etag":null,"topics":["java","rest-api","restclient","unirest"],"latest_commit_sha":null,"homepage":null,"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/joshgontijo.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":null,"security":null,"support":null}},"created_at":"2017-05-12T20:50:48.000Z","updated_at":"2023-11-23T23:33:27.000Z","dependencies_parsed_at":"2022-08-23T20:31:04.104Z","dependency_job_id":null,"html_url":"https://github.com/joshgontijo/rest-client","commit_stats":null,"previous_names":["josueeduardo/rest-client"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/joshgontijo/rest-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshgontijo%2Frest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshgontijo%2Frest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshgontijo%2Frest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshgontijo%2Frest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshgontijo","download_url":"https://codeload.github.com/joshgontijo/rest-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshgontijo%2Frest-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30469321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["java","rest-api","restclient","unirest"],"created_at":"2024-11-05T14:30:48.770Z","updated_at":"2026-03-13T15:38:03.709Z","avatar_url":"https://github.com/joshgontijo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RestClient - [Unirest](https://github.com/Mashape/unirest-java) fork\n\nThis fork is intended to fix the bugs left by the original authors, improve the API, and provide continuous support.\nImprovements, new ideas, and bug reports are always welcome. The  \n\n\n[![License][license-image]][license-url]\n\n\n## Features\n\nApart from the features provided by the original Unirest Java, this fork also has:\n\n* Updated API to make use of Java 8\n* Major Bug fixes\n* Support for multiple independent clients\n* General API improvements\n* Updated async requests to use Java 8 CompletableFuture\n* Lazy response body parsing\n* Default Gson parser \n\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.joshworks.unirest\u003c/groupId\u003e\n    \u003cartifactId\u003eunirest-java\u003c/artifactId\u003e\n    \u003cversion\u003e1.7.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Creating a new client with defaults\nThe following example creates a new basic RestClient instance. At the moment, each client will have its own \nHttpClient sync and async client.\n\n```java\n\nRestClient client = RestClient.builder().build();\n\n```\n\n## Creating Request\n\n```java\n\nRestClient client = RestClient.builder().build();\n\nHttpResponse\u003cJsonNode\u003e jsonResponse = client.post(\"http://httpbin.org/post\")\n  .header(\"accept\", \"application/json\")\n  .queryString(\"apiKey\", \"123\")\n  .asJson();\n```\n\n### Base url\n\n```java\n\nRestClient client = RestClient.builder().baseUrl(\"http://my-api.com/v1\").build();\nString response = client.get(\"/some-resource\").asString();\n\n```\n\n### Unirest client\nUnirest provides the same static methods as the original version. It's ideal for simple usage with default configuration. \n\n```java\n\nString response = Unirest.get(\"http://my-api.com/v1\").asString();\n\n```\n\n### Path parameters\nWith the new API, there's no need to concatenate path parameters, making the it easier and much more convenient to use.\nYou can either provide a varargs path. Or you can use a template and then use `.routeParam()` to specify its values.\n```java\n\n//Sends a request to http://my-api.com/v1/users\nString response = client.post(\"http://my-api.com\", \"v1\", \"users\").asString();\n\n//Alternatively\n\n//Also Sends a request to http://my-api.com/v1/users\nString response = client.get(\"http://my-api.com/{verion}/{endpoint}\")\n  .routeParam(\"verion\", \"v1\")\n  .routeParam(\"endpoint\", \"users\")\n  .asString();\n\n```\n\n\n### Async requests with CompletableFuture\nWhen using asynchronous requests you can use Java 8 CompletableFuture to handle the response.\nThis also gives you the ability to compose multiple requests in a convenient way. \n\n```java\nclient.get(\"http://my-api.com/v1/hello\")\n        .asStringAsync()\n        .thenAccept(resp -\u003e {\n            System.out.println(resp.body())\n         })\n         .exceptionally(e -\u003e {\n            e.printStackTrace();\n            return null;\n         });\n         \n```\n\n### New multipart/form-data and x-www-form-urlencoded API\nThe new API for form data makes easier to specify the right values for each type of request. When using `.part(...)` a \n`multipart/form-data` request will be sent, `.field(...)` will create `x-www-form-urlencoded` request. This makes the interface cleaner and less error prone.\nThe content type is also set automatically.\n\n```java\n//multipart\nclient.post(\"http://my-service.com/fileUpload\")\n        .part(\"param3\", value)\n        .part(\"file\", new File(\"test.txt\"))\n        .asJson();\n\n//form-urlencoded\nclient.post(\"http://my-service.com/login\")\n                .field(\"username\", \"admin\")\n                .field(\"password\", \"admin123\")\n                .asJson();\n\n```\n\n### Serialization\nBefore using `asObject(Class)` or `.body(Object)`, is necessary to provide a custom implementation of the `ObjectMapper` interface.\nThis should be done for each client.\nJson is supported out-of-the-box, so there's no need to register any other json mapper unless you want a custom configuration.\nHere's how to configure a new ObjectMapper:\n\n```java\npublic class XmlMapper implements ObjectMapper {\n   \n    @Override\n    public \u003cT\u003e T readValue(String value, Class\u003cT\u003e valueType) {\n        //...\n    }\n\n    @Override\n    public String writeValue(Object value) {\n        //...\n    }\n}\n\nObjectMappers.register(MediaType.APPLICATION_XML_TYPE, new XmlMapper());\n\n\nHttpResponse\u003cUser\u003e response = client.post(\"http://my-api.com/echo-xml\")\n                .header(\"Accept\", \"application/xml\")\n                .header(\"Content-Type\", \"application/xml\")\n                .body(new User(\"John\"))\n                .asObject(User.class);\n\n```\n\n### Client stats\nThe API also exposes HttpClient's PoolStats, so you can inspect the usage of each client.\n\n```java\n   \n   ClientStats stats = client.stats();\n   int leased = stats.sync.getLeased();\n   int available = stats.sync.getAvailable();\n   int max = stats.sync.getMax();\n   int pending = stats.sync.getPending();\n\n   //All clients\n   Map\u003cString, ClientStats\u003e allStats = ClientContainer.stats();\n   //...\n\n```\n\n# Exiting an application\n\nRestClient starts a background idle thread monitor, which is a daemon thread. \nWhen exiting the application, you can use the `ClientContainer` to release all the allocated resources, as follows:\n\n```java\n//If a client is no longer needed and you want to dispose its resources\nclient.shutdown();\n\n//When your application is shutting down:\n//Closes all client connections and the monitor\nClientContainer.shutdown();\n\n```\n\n[license-url]: https://github.com/josueeduardo/rest-client/blob/master/LICENSE\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshgontijo%2Frest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshgontijo%2Frest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshgontijo%2Frest-client/lists"}