{"id":19888892,"url":"https://github.com/paypal/paypalhttp_java","last_synced_at":"2025-06-18T05:35:01.348Z","repository":{"id":44660677,"uuid":"212699428","full_name":"paypal/paypalhttp_java","owner":"paypal","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-06T17:39:35.000Z","size":264,"stargazers_count":8,"open_issues_count":6,"forks_count":19,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-02T17:59:06.209Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paypal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-03T23:22:02.000Z","updated_at":"2023-10-16T10:13:24.000Z","dependencies_parsed_at":"2023-01-19T13:46:49.302Z","dependency_job_id":null,"html_url":"https://github.com/paypal/paypalhttp_java","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/paypal/paypalhttp_java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paypal","download_url":"https://codeload.github.com/paypal/paypalhttp_java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260495644,"owners_count":23017933,"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":[],"created_at":"2024-11-12T18:08:34.536Z","updated_at":"2025-06-18T05:34:56.332Z","avatar_url":"https://github.com/paypal.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PayPal HttpClient\n\nPaypalHttp is a generic HTTP Client.\n\nIn it's simplest form, an [`HttpClient`](./paypalhttp/src/main/java/com/paypal/http/HttpClient.java) exposes an `#execute` method which takes an `HttpRequest`, executes it against the domain described in an `Environment`, and returns an `HttpResponse`. It throws an `IOException` if anything goes wrong during execution.\n\n### Environment\n\nAn [`Environment`](./paypalhttp/src/main/java/com/paypal/http/Environment.java) describes a domain that hosts a REST API, against which an `HttpClient` will make requests. `Environment` is a simple interface that wraps one method, `#baseUrl`.\n\n```java\nEnvironment env = () -\u003e \"https://example.com\";\n```\n\n### Requests\n\n[`HttpRequest`](./paypalhttp/src/main/java/com/paypal/http/HttpRequest.java)s contain all the information needed to make an HTTP request against the REST API. Specifically, one request describes a path, a verb, any path/query/form parameters, headers, attached files for upload, and body data. This class also holds a reference to the type of the response for deserializtion, if a structured response is expected.\n\n### Responses\n\n[`HttpResponse`](./paypalhttp/src/main/java/com/paypal/http/HttpResponse.java)s contain information returned by a server in response to a request as described above. They contain a status code, headers, and any data returned by the server, deserialized in accordance with the type in the `HttpRequest` from which this reponse originated.\n\n```java\nHttpRequest\u003cMyResponsePojo\u003e req = new HttpRequest(\"/path/to/resource\", \"GET\", MyResponsePojo.class);\n\nHttpResponse\u003cMyResponsePojo\u003e resp = client.execute(req);\n\nInteger statusCode = resp.statusCode();\nHeaders headers = resp.headers();\nMyResponsePojo responseData = resp.result();\n```\n\n### Injectors\n\n[`Injector`](./paypalhttp/src/main/java/com/paypal/http/Injector.java)s wrap closures that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. `Injector`s are attached to an `HttpClient` using the `#addInjector` method.\n\nThe HttpClient executes its `Injector`s in a first-in, first-out order, before each request.\n\n```java\nHttpClient client = new HttpClient(env);\n\nclient.addInjector(req -\u003e {\n  log.log(req);\n});\n\nclient.addInjector(req -\u003e {\n  req.headers().header(\"Request-Id\", \"abcd\");\n});\n\n...\n```\n\n### Error Handling\n\n`HttpClient#execute` may throw an `IOException` if something went wrong during the course of execution. If the server returned a non-200 response, this execption will be an instance of [`HttpException`](./paypalhttp/src/main/java/com/paypal/http/exceptions/HttpException.java) that will contain a status code and headers you can use for debugging. \n\n```java\ntry {\n  HttpResponse\u003cMyResponsePojo\u003e resp = client.execute(req);\n} catch(IOException ioe) {\n  if (ioe instanceof HttpException) {\n    // Inspect this exception for details\n    HttpException he = (HttpException) ioe;\n    int statusCode = ioe.statusCode();\n  } else {\n    // Something else went wrong\n  }\n}\n```\n\n### Serializer\n(De)Serialization of request and response data is done by implementations of the [`Serializer`](./paypalhttp/src/main/java/com/paypal/http/serializer/Serializer.java) interface. PaypalHttp currently supports `json` encoding out of the box.\n\n### SSL\n\nBy default, PaypalHttp will use the built-in `TLSSoccketFactory` when connecting to URLs that use `https` as their scheme. If you'd like to do cert-pinning, or use a different SSL implementation, you can provide your own `SSLSocketFactory` via `HttpClient#setSSLSocketFactory()`.\n\n## License\n\nPaypalHttp-Java is open source and available under the MIT license. See the [LICENSE](./LICENSE) file for more info.\n\n\n## Contributions\nPull requests and new issues are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaypal%2Fpaypalhttp_java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaypal%2Fpaypalhttp_java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaypal%2Fpaypalhttp_java/lists"}