{"id":22349712,"url":"https://github.com/crissnamon/http-interface-client","last_synced_at":"2025-03-26T11:22:53.260Z","repository":{"id":65288631,"uuid":"589289498","full_name":"CrissNamon/http-interface-client","owner":"CrissNamon","description":"Simple HTTP client to make requests using interfaces","archived":false,"fork":false,"pushed_at":"2023-01-16T20:22:44.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T12:35:04.138Z","etag":null,"topics":["feign","http","http-client","java","kotlin","rest","rest-client","web"],"latest_commit_sha":null,"homepage":"https://github.com/CrissNamon/http-interface-client/wiki","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CrissNamon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-15T17:38:46.000Z","updated_at":"2023-01-15T18:33:57.000Z","dependencies_parsed_at":"2023-02-10T06:00:57.232Z","dependency_job_id":null,"html_url":"https://github.com/CrissNamon/http-interface-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissNamon%2Fhttp-interface-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissNamon%2Fhttp-interface-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissNamon%2Fhttp-interface-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrissNamon%2Fhttp-interface-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrissNamon","download_url":"https://codeload.github.com/CrissNamon/http-interface-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245641728,"owners_count":20648723,"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":["feign","http","http-client","java","kotlin","rest","rest-client","web"],"created_at":"2024-12-04T11:09:02.004Z","updated_at":"2025-03-26T11:22:53.240Z","avatar_url":"https://github.com/CrissNamon.png","language":"Java","readme":"## HTTP interface client\n\n### About\n\nSimple library to perform http requests using interfaces with no implementations.\n\n### Documentation\n\nSee [Wiki](https://github.com/CrissNamon/http-interface-client/wiki) for more documentation and examples.\n\n### How to use\n\nCreate interface and methods for requests.\nAnnotate methods and their parameters with library annotations:\n\n```java\npublic interface BookClient {\n\n  @GET(\"/book\")\n  List\u003cBook\u003e getBooks(@Query(\"page\") Integer page);\n\n  @GET(\"/book/{id}\")\n  Book getBook(@Path(\"id\") Integer id);\n\n  @POST(\"/book\")\n  Book createBook(@Header(\"Content-Type\") String contentType, @Body Book newBook);\n\n  @PUT(\"/book/{id}\")\n  Book updateBook(@Path(\"id\") Integer id, @Body Book book);\n\n  @DELETE(\"/book/{id}\")\n  void deleteBook(@Path(\"id\") Integer id);\n\n  @GET(\"/book\")\n  CompletableFuture\u003cList\u003cBook\u003e\u003e getBooksAsync();\n\n  @POST(value = \"/book\", contentType = RequestContent.FORM_ENCODED)\n  Book createBookFromForm(@Field(\"title\") String title);\n\n  @POST(value = \"/book\", contentType = RequestContent.MULTIPART)\n  Book createBookFromFile(@Part(\"file\") MultipartData file);\n}\n```\n\nCreate ``WebClient`` instance from created interface and then just call interface methods:\n\n```java\npublic class Main {\n\n  public static void main(String... args) throws ExecutionException, InterruptedException {\n\n    // Create WebClient\n    BookClient bookClient = WebClient.of(BookClient.class)\n        // Set base url\n        .baseUrl(\"https://63c306edb0c286fbe5f7e9d4.mockapi.io/api/v1\")\n        // Set body decoder (optional, GSON by default)\n        .decoder(new JSONBodyDecoder())\n        // Set body encoder (optional, GSON by default) \n        .encoder(new JSONBodyEncoder())\n        // Set WebClient exception handler (optional)\n        .exceptionHandler(new DefaultExceptionHandler())\n        // Add new header (optional)\n        .header(\"Authorization\", Main::authorizationBearerToken)\n        // Set HttpRequest handler (optional)\n        .httpHandler(Response::isError, new DefaultHttpErrorHandler())\n        .create();\n\n    // Get all books\n    List\u003cBook\u003e allBooks = bookClient.getBooks(1);\n    System.out.println(allBooks);\n\n    // Get book with id = 3\n    Book someBook = bookClient.getBook(3);\n    System.out.println(someBook);\n\n    //Create new book\n    Book newBook = new Book(\"New book\");\n    System.out.println(bookClient.createBook(\"application/json\", newBook));\n\n    // Update book with id = 5\n    System.out.println(bookClient.updateBook(5, newBook));\n\n    // Get all books async\n    bookClient.getBooksAsync()\n        .whenComplete((books, throwable) -\u003e System.out.println(books))\n        .get();\n\n    // Get wrapped response\n    Response\u003cList\u003cBook\u003e\u003e allBooksWrapped = bookClient.getBooksWrapped();\n    System.out.println(\"Is wrapped error: \" + allBooksWrapped.isError());\n    System.out.println(\"Raw unwrapped: \" + allBooksWrapped.raw());\n    System.out.println(\"Unwrapped: \" + allBooksWrapped.get());\n\n    // Create book with Content-Type: application/x-www-form-urlencoded\n    bookClient.createBookFromForm(\"The peripheral\");\n\n    // Create book with Content-Type: multipart/form-data\n    File file = new File(\"file.txt\");\n    MultipartData multipartFile = new MultipartFile(file.toPath());\n    bookClient.createBookFromFile(multipartFile);\n  }\n\n  public static String authorizationBearerToken() {\n    return \"Bearer token\";\n  }\n\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrissnamon%2Fhttp-interface-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrissnamon%2Fhttp-interface-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrissnamon%2Fhttp-interface-client/lists"}