{"id":19888833,"url":"https://github.com/paypal/paypalhttp_node","last_synced_at":"2025-05-07T09:47:11.679Z","repository":{"id":47070379,"uuid":"212699662","full_name":"paypal/paypalhttp_node","owner":"paypal","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-28T04:06:39.000Z","size":104,"stargazers_count":7,"open_issues_count":7,"forks_count":9,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-04T00:29:34.973Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-03T23:23:57.000Z","updated_at":"2025-04-16T12:22:07.000Z","dependencies_parsed_at":"2024-06-18T16:57:58.765Z","dependency_job_id":"643bb36e-2100-4a9e-9363-920e199476d1","html_url":"https://github.com/paypal/paypalhttp_node","commit_stats":{"total_commits":71,"total_committers":12,"mean_commits":5.916666666666667,"dds":0.6901408450704225,"last_synced_commit":"4cbb1e88069227048d2636cfbda68d4b20014356"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paypal%2Fpaypalhttp_node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paypal","download_url":"https://codeload.github.com/paypal/paypalhttp_node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252854337,"owners_count":21814669,"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:25.482Z","updated_at":"2025-05-07T09:47:11.661Z","avatar_url":"https://github.com/paypal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PayPal HttpClient\n\nPayPalHttp is a generic HTTP Client.\n\nIn it's simplest form, an [`HttpClient`](lib/paypalhttp/http_client.js) exposes an `#execute` method which takes an `HttpRequest`, executes it against the domain described in an `Environment`, and returns a Promise.\n\n### Environment\n\nAn [`Environment`](lib/paypalhttp/environment.js) describes a domain that hosts a REST API, against which an `HttpClient` will make requests. `Environment` is a simple class that contains one property, `baseUrl`.\n\n```js\nlet env = new Environment('https://example.com');\n```\n\n### Requests\n\nHTTP requests 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. In Javascript, an HttpRequest is simply an object literal with `path`, `verb`, and optionally, `requestBody`, and `headers` populated.\n\n### Responses\n\nHTTP responses contain information returned by a server in response to a request as described above. They are simple objects which contain a `statusCode`, `headers`, and a `result`, which represents any data returned by the server.\n\n```js\nlet req = {\n  path: \"/path/to/resource\",\n  verb: \"GET\",\n  headers: {\n    \"X-Custom-Header\": \"custom value\"\n  }\n}\n\nclient.execute(req)\n  .then((resp) =\u003e {\n    let statusCode = resp.statusCode;\n    let headers = resp.headers;\n    let responseData = resp.result;\n  });\n```\n\n### Injectors\n\nInjectors are closures that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. Injectors are attached to an `HttpClient` using the `#addInjector` method. They must take one argument (a request), and may return nothing, or a Promise.\n\nThe `HttpClient` executes its injectors in a first-in, first-out order, before each request.\n\n```js\nlet client = new HttpClient(env);\nclient.addInjector((req) =\u003e {\n  console.log(req);\n});\n\nclient.addInjector((req) =\u003e {\n  req.headers['Request-Id'] = 'abcd';\n});\n\n...\n```\n\n### Error Handling\n\nThe Promise returned by `HttpClient#execute` maybe be rejected if something went wrong during the course of execution. If the server returned a non-200 response, this error will be an object that contains a status code, headers, and any data that was returned for debugging.\n\n```js\nclient.execute(req)\n  .then((resp) =\u003e {\n    let statusCode = resp.statusCode;\n    let headers = resp.headers;\n    let responseData = resp.result;\n  })\n  .catch((err) =\u003e {\n    if (err.statusCode) {\n      let statusCode = err.statusCode;\n      let headers = err.headers;\n      let message = err.message;\n    } else {\n      // Something else went wrong\n      console.err(err);\n    }\n  });\n```\n\n### Serializer\n(De)Serialization of request and response data is done by instances of [`Encoder`](lib/paypalhttp/encoder.js). PayPalHttp currently supports `json` encoding out of the box.\n\n## License\nPayPalHttp-Node is open source and available under the MIT license. See the [LICENSE](./LICENSE) file for more info.\n\n## Contributing\nPull requests and issues are welcome. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaypal%2Fpaypalhttp_node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaypal%2Fpaypalhttp_node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaypal%2Fpaypalhttp_node/lists"}