{"id":37027858,"url":"https://github.com/libedi/rest-request","last_synced_at":"2026-01-14T03:19:04.401Z","repository":{"id":39651092,"uuid":"410892873","full_name":"libedi/rest-request","owner":"libedi","description":"HTTP Request Generator for RestTemplate","archived":false,"fork":false,"pushed_at":"2023-10-12T19:46:59.000Z","size":114,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-30T19:32:27.659Z","etag":null,"topics":["http-client","java","rest","resttemplate","spring","spring-web","springframework","springweb"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libedi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-09-27T13:20:59.000Z","updated_at":"2022-01-02T12:47:02.000Z","dependencies_parsed_at":"2023-10-13T12:46:39.602Z","dependency_job_id":null,"html_url":"https://github.com/libedi/rest-request","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/libedi/rest-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libedi%2Frest-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libedi%2Frest-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libedi%2Frest-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libedi%2Frest-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libedi","download_url":"https://codeload.github.com/libedi/rest-request/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libedi%2Frest-request/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["http-client","java","rest","resttemplate","spring","spring-web","springframework","springweb"],"created_at":"2026-01-14T03:19:03.960Z","updated_at":"2026-01-14T03:19:04.382Z","avatar_url":"https://github.com/libedi.png","language":"Java","readme":"# **rest-request**\n***rest-request*** is a tool that makes it easy to create many parameters that need to be generated when using Spring Web's `RestTemplate`.  \n\n***rest-request*** is inspired by Spring Webflux's `WebClient`, which similarly allows method-chaining methods to create HTTP Headers, Query Parameters, Form Data, Request Body, and more.\n~~~java\nRestRequest\u003cResponseType\u003e request = RestRequest.resp(ResponseType.class)\n                                               .uri(\"http://www.api.com/resources\")\n                                               .post()\n                                               .addHeader(\"X-Test-Header-Name\", \"XTestHeaderValue\")\n                                               .addParam(\"queryParamKey\", \"queryParamValue\")\n                                               .body(requestBodyObject)\n                                               .build();\nResponsType response = restTemplate.exchange(request.getUri(),\n                                             request.getMethod(),\n                                             request.getHttpEntity(),\n                                             request.getResponseType());\n~~~\nAs above, you can easily and readably generate all the information you need for `RestTemplate`.\n\n## **How to create `RestRequest`**\n***rest-request*** provides `RestRequest` object that creates request information, and generated in the following order:\n\n### **1. Response Type**\nThere are four types of responses:\n- 1. Preference : `Map\u003cString, Object\u003e`\n- 2. T type : `Class\u003cT\u003e`\n- 3. Generic T type : `ParameterizedTypeReference\u003cT\u003e`\n- 4. Void type : `Class\u003cVoid\u003e`\n~~~java\n// 1. Preference : Map\u003cString, Object\u003e\nRestRequest.mapResp()\n\n// 2. T type : Class\u003cT\u003e\nRestRequest.resp(ResponseType.class)\n\n// 3. Generic T type : ParameterizedTypeReference\u003cT\u003e\nRestRequest.resp(new ParameterizedTypeReference\u003cList\u003cResponseType\u003e\u003e(){})\n\n// 4. Void type : Class\u003cVoid\u003e\nRestRequest.nonResp()\n~~~\n\n### **2. Request URI**\nThe URI to request supports paramters of the `java.net.URI` or `String` type.\n~~~java\n// java.net.URI type\nURI uri = URI.create(\"http://www.api.com/resources\");\nRestRequest.resp(ResponseType.class)\n           .uri(uri)\n\n// String type\nRestRequest.resp(ResponseType.class)\n           .uri(\"http://www.api.com/resources\")\n~~~\n\n### **3. HTTP Method**\nHTTP Method can be specified by a method name with an intuitive name. The methods that supports it are GET / POST / PUT / PATCH / DELETE. Here, the POST / PUT / PATCH method allows you to set the Request Body in the near time.\n~~~java\nRestRequest.resp(ResponseType.class)\n           .uri(uri)\n           .get() / .post() / .put() / .patch() / .delete()\n~~~\n\n### **4. HTTP Headers / Query Parameters / Form Datas / Request Body**\nAfterwards, you can set HTTP Headers, Query Parameters, Form Datas, and Request Body.\n\n- **HTTP Header**  \nHTTP Header can be added as an **`addHeader()`, `accept()`, `contentType()`, `authorization()`, `basicAuth()`** and **`bearerToken()`** methods.\n    ~~~java\n    RestRequest.resp(ResponseType.class)\n               .uri(uri)\n               .get()\n               .addHeader(\"headerName\", \"headerValue\")\n               .accept(MediaType.APPLICATION_JSON)  // Support type : MediaType, String\n               .contentType(\"application/json\")     // Support type : MediaType, String\n               .authorization(\"authValue\")\n               .basicAuth(\"username\", \"password\")\n               .bearerToken(\"tokenValue\")\n    ~~~\n- **Form Parameter**  \nYou can add Form Parameters with the **`addParam()`, `setParams()`** methods.  \nIf you previously specified `get()` / `delete()`, Query Parameter is generated, and if `post()` / `put()` / `patch()` is specified, Form Data is generated.  \nIf both Request Body and Form Parameter are set, they are generated as Query Parameters, even if `post()` / `put()` / `patch()` is specified.\n    ~~~java\n    // Generate a Query Parameter\n    RestRequest.resp(ResponseType.class)\n               .uri(uri)\n               .get()\n               .addParam(\"paramKey\", \"paramValue\")  // Add Query Parameter : key-value\n               .setParams(multiValueMap)            // Add Query Parameter : MultiValueMap\u003cString, Object\u003e\n               .setParams(map)                      // Add Query Parameter : Map\u003cString, Object\u003e\n               .setParams(object)                   // Add Query Parameter : Object\n\n    // Generate Form Datas\n    RestRequest.resp(ResponseType.class)\n               .uri(uri)\n               .post()\n               .addParam(\"paramKey\", \"paramValue\")\n    ~~~\n- **Request Body**  \nYou can set it as a **`body()`** method. (You can call the `body()` method only when specifying `post()` / `put()` / `patch()` methods.)\n    ~~~java\n    RestRequest.resp(ResponseType.class)\n               .put()\n               .addParam(\"queryParamKey\", \"queryParamValue\")  // Generate Query Parameter\n               .body(requestBodyObject)\n    ~~~\n- **Attach File**  \nYou can set it as a **`addFile()`** method. The supported parameter types are `File`, `Path`, and `MultipartFile`. If the Content Type header is not set, it is automatically set to the value `multipart/form-data`.\n    ~~~java\n    RestRequest.resp(ResponseType.class)\n               .post()\n               .addFile(\"file1\", new File(\"test.txt\"))\n               .addFile(\"file2\", Paths.get(\"test.txt\"))\n               .addFile(\"file3\", multipartFile)\n    ~~~\n    If Request Body is set, it is set to `multipart/mixed`. However, since Request Body is set as a key called `body` in the form data, it is recommended to set it directly using `addParam()` if possible. (You can call the `addFile()` method only when specifying `post()` / `put()` / `patch()` methods.)\n    ~~~java\n    RestRequest.resp(ResponseType.class)\n               .uri(uri)\n               .post()\n               .contentType(MediaType.MULTIPART_MIXED)\n               .addParam(\"json\", new ObjectMapper().writeValueAsString(body))\n               .addFile(\"attach\", Paths.get(\"test.txt\"))\n               .build();\n    ~~~\n\n### **5. build()**\nFinally, call **`build()`** method to generate `RestRequest`.  \n`RestRequest` can load the following properties:\n- `URI`\n- `HttpMethod`\n- `HttpEntity`\n- `Class\u003cT\u003e`\n- `ParameterizedTypeReference\u003cT\u003e`\n~~~java\n// Class\u003cT\u003e when specifying\nRestRequest\u003cResponseType\u003e request = RestRequest.resp(ResponseType.class)\n                                               .uri(uri)\n                                               .get()\n                                               .build();\nResponseType response = restTemplate.exchange(request.getUri(),\n                                              request.getMethod(),\n                                              request.getHttpEntity(),\n                                              request.getResponseType());\n\n// ParameterizedTypeReference\u003cT\u003e when specifying\nRestRequest\u003cList\u003cResponseType\u003e\u003e request = RestRequest.resp(new ParameterizedTypeReference\u003cList\u003cResponseType\u003e\u003e(){})\n                                                     .uri(uri)\n                                                     .get()\n                                                     .build();\nList\u003cResponseType\u003e response = restTemplate.exchange(request.getUri(),\n                                                    request.getMethod(),\n                                                    request.getHttpEntity(),\n                                                    request.getTypeReference());\n~~~\n\n## **RestClientAdapter**\n***rest-request*** provides **`RestClientAdapter`**, a class that works with `RestRequest` and `RestTemplate`.  \n**`RestClientAdapter`** can be generated as a Bean in two ways:\n~~~java\n@Configuration\npublic class WebConfig {\n    @Bean\n    @ConditionalOnMissingBean(RestTemplate.class)\n    public RestClientAdapter restClientAdapter() {\n        return new DefaultRestClientAdpater();\n    }\n    \n    @Bean\n    @ConditionalOnBean(RestTemplate.class)\n    public RestClientAdapter restClientAdapter(final RestTemplate restTemplate) {\n        return new DefaultRestClientAdapter(restTemplate);\n    }\n}\n~~~\n`DefaultRestClientAdapter` default constructor is internally generated using `new RestTemplate()`.  \nOr, if you have `RestTemplate` generated by Bean, you're injected with that `RestTemplate`.  \n  \n**`RestClientAdapter`** can be used as follows:\n~~~java\n@Service\npublic class WebService {\n    @Autowired\n    private RestClientAdpater restClient;\n    \n    public ResponseEntity\u003cResource\u003e getSome(ResourceDto dto) {\n        return restClient.send(RestRequest.resp(Resource.class)\n                                          .uri(\"http://www.api.com/resources\")\n                                          .get()\n                                          .setParams(dto)\n                                          .build());\n    }\n    \n    public Optional\u003cResource\u003e postSome(Resource resource) {\n        return restClient.sendForBody(RestRequest.resp(Resource.class)\n                                                 .uri(\"http://www.api.com/resources\")\n                                                 .post()\n                                                 .body(resource)\n                                                 .build());\n    }\n\n    public CompletableFuture\u003cResponseEntity\u003cResource\u003e\u003e getSomeAsync(ResourceDto dto) {\n        return restClient.sendAsync(RestRequest.resp(Resource.class)\n                                               .uri(\"http://www.api.com/resources\")\n                                               .get()\n                                               .setParams(dto)\n                                               .build());\n    }\n\n    public CompletableFuture\u003cResponseEntity\u003cResource\u003e\u003e getSomeAsync(ResourceDto dto, Executor executor) {\n        return restClient.sendAsync(RestRequest.resp(Resource.class)\n                                               .uri(\"http://www.api.com/resources\")\n                                               .get()\n                                               .setParams(dto)\n                                               .build(),\n                                    executor);\n    }\n}\n~~~\n\n## **Requirements**\n- Java 8 or higher\n- Spring Web 5.3.25 or higher\n\n## **Installation**\n- ### **Maven**\n~~~xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.libedi\u003c/groupId\u003e\n    \u003cartifactId\u003erest-request\u003c/artifactId\u003e\n    \u003cversion\u003e2.1.2\u003c/version\u003e\n\u003c/dependency\u003e\n~~~\n- ### **Gradle**\n~~~groovy\nimplementation 'io.github.libedi:rest-request:2.1.2'\n~~~\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibedi%2Frest-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibedi%2Frest-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibedi%2Frest-request/lists"}