{"id":29291097,"url":"https://github.com/networknt/http-client","last_synced_at":"2025-07-30T09:04:59.088Z","repository":{"id":45294351,"uuid":"428730593","full_name":"networknt/http-client","owner":"networknt","description":"An HTTP client based on JDK 11 http-client to invoke APIs with client-side cross-cutting concerns addressed","archived":false,"fork":false,"pushed_at":"2025-07-17T19:04:25.000Z","size":173,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-07-17T22:45:13.023Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/networknt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-11-16T16:24:25.000Z","updated_at":"2025-07-17T19:03:37.000Z","dependencies_parsed_at":"2024-02-14T16:28:49.123Z","dependency_job_id":"9f773eb1-0475-453a-8a7f-e5f1b5da07b7","html_url":"https://github.com/networknt/http-client","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/networknt/http-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networknt%2Fhttp-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networknt%2Fhttp-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networknt%2Fhttp-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networknt%2Fhttp-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/networknt","download_url":"https://codeload.github.com/networknt/http-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networknt%2Fhttp-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267842978,"owners_count":24153133,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"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":[],"created_at":"2025-07-06T07:34:19.884Z","updated_at":"2025-07-30T09:04:59.073Z","avatar_url":"https://github.com/networknt.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-client\n\n\nAn HTTP client based on JDK 11 http-client to invoke APIs with client-side cross-cutting concerns addressed\n\nThe purpose of the client module is trying to help the user to handler SSL cert load and JWT token process.\n\n###  Synchronous call\n\n```text\n        HttpClientRequest httpClientRequest = new HttpClientRequest();\n        HttpRequest.Builder builder = httpClientRequest.initBuilder(\"https://localhost:8445/v1/pets\", HttpMethod.GET);\n        builder.setHeader(\"x-traceability-id\", \"1111111\");\n        HttpResponse\u003cString\u003e response = (HttpResponse\u003cString\u003e) httpClientRequest.send(builder, HttpResponse.BodyHandlers.ofString());\n        int responseStatus = response.statusCode();\n        String responseBody = response.body();\n```\n\n###  Synchronous call by adding jwt token to the header\n\n```text\n        HttpClientRequest httpClientRequest = new HttpClientRequest();\n        HttpRequest.Builder builder = httpClientRequest.initBuilder(\"https://localhost:8445/v1/pets\", HttpMethod.GET);\n        builder.setHeader(\"x-traceability-id\", \"1111111\");\n        httpClientRequest.addCcToken(builder);\n        HttpResponse\u003cString\u003e response = (HttpResponse\u003cString\u003e) httpClientRequest.send(builder, HttpResponse.BodyHandlers.ofString());\n        int responseStatus = response.statusCode();\n        String responseBody = response.body();\n```\n\n###  Asynchronous call with jwt token\n\n```text\n        HttpClientRequest httpClientRequest = new HttpClientRequest();\n        HttpRequest.Builder builder = httpClientRequest.initBuilder(\"https://localhost:8445/v1/pets\", HttpMethod.GET);\n        builder.setHeader(\"x-traceability-id\", \"1111111\");\n        httpClientRequest.addCcToken(builder);\n        CompletableFuture\u003cHttpResponse\u003cString\u003e\u003e response = (CompletableFuture\u003cHttpResponse\u003cString\u003e\u003e )httpClientRequest.sendAsync(builder, HttpResponse.BodyHandlers.ofString());\n        // print response body\n        System.out.println(response.get().body());\n```\n\n###  POST method call by adding jwt token to the header\n\n```text\n        httpClientRequest = new HttpClientRequest();\n        String requestBody = \"{\\\"name\\\": \\\"doggie1\\\"}\";\n        HttpRequest.Builder builder = httpClientRequest.initBuilder(\"https://localhost:8445/v1/pets\", HttpMethod.POST, Optional.of(requestBody));\n        builder.setHeader(\"x-traceability-id\", \"1111111\");\n        builder.setHeader(\"Content-Type\", \"application/json\");\n        httpClientRequest.addCcToken(builder);\n        HttpResponse\u003cString\u003e response = (HttpResponse\u003cString\u003e) httpClientRequest.send(builder, HttpResponse.BodyHandlers.ofString());\n        System.out.println(response.statusCode());\n        System.out.println(response.body());\n```\n\n### Connectionpool\n\nJDK 11 http connection build connection pool internal and it will select the connection from pool base on certain logic.\n\n\n### Connection with proxy.\n\nIf the connection need bridge with proxy, then we need set the proxy for httpClient first:\n\n```text\n        httpClientRequest = new HttpClientRequest();\n        httpClientRequest.setProxy(\"https://internal.proxy.com\", \"443\")\n```\nThe token access request will handler proxy based on the proxy setting on the client.yml file:\n\n```text\noauth:\n  # OAuth 2.0 token endpoint configuration\n  token:\n    # token service unique id for OAuth 2.0 provider. If server_url is not set above,\n    # a service discovery action will be taken to find an instance of token service.\n    serviceId: com.networknt.oauth2-token-1.0.0\n    # set to true if the oauth2 provider supports HTTP/2\n    # For users who leverage SaaS OAuth 2.0 provider from lightapi.net or others in the public cloud\n    # and has an internal proxy server to access code, token and key services of OAuth 2.0, set up the\n    # proxyHost here for the HTTPS traffic. This option is only working with server_url and serviceId\n    # below should be commented out. OAuth 2.0 services cannot be discovered if a proxy server is used.\n    proxyHost:\n    # We only support HTTPS traffic for the proxy and the default port is 443. If your proxy server has\n    # a different port, please specify it here. If proxyHost is available and proxyPort is missing, then\n    # the default value 443 is going to be used for the HTTP connection.\n    proxyPort:\n```\n\nIf the proxyHost set value in the client.yml, the token access will send request call with proxy.\n\n### Connection with HTTP authentication.\n\nIf request call need HTTP authentication, sets an authenticator to use for HTTP authentication.\n\nFor example:\n\n```text\n            Authenticator  authenticator = new Authenticator() {\n                @Override\n                protected PasswordAuthentication getPasswordAuthentication() {\n                    return new PasswordAuthentication(\n                            \"user\",\n                            \"password\".toCharArray());\n                }\n        httpClientRequest = new HttpClientRequest();\n        httpClientRequest.setAuthenticator(authenticator);\n```\n\n### TLS context load info\n\nJava HttpClient by default will load default JDK cacerts for https request, if the API call doesn't include self-signed cert, we can leave the :\n\n```\n  # trust store contains certifictes that server needs. Enable if tls is used.\n  loadTrustStore: false\n```\n\nIf we need load self-signed trust from client truststore, set the config value to true:\n\n```\n  # trust store contains certifictes that server needs. Enable if tls is used.\n  loadTrustStore: true\n```\n\nSystem will load the client truststore and default certs together for SSL context\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworknt%2Fhttp-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetworknt%2Fhttp-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworknt%2Fhttp-client/lists"}