{"id":27247736,"url":"https://github.com/idleray/prhttp","last_synced_at":"2025-04-10T22:58:40.143Z","repository":{"id":57330263,"uuid":"391608551","full_name":"idleray/prhttp","owner":"idleray","description":"A JavaScript HTTP interceptor","archived":false,"fork":false,"pushed_at":"2023-12-01T08:40:53.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T22:58:35.076Z","etag":null,"topics":["http","interceptor","javascript","lifecycle","nodejs"],"latest_commit_sha":null,"homepage":"","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/idleray.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}},"created_at":"2021-08-01T11:26:11.000Z","updated_at":"2022-10-21T16:29:08.000Z","dependencies_parsed_at":"2023-12-01T09:34:09.659Z","dependency_job_id":null,"html_url":"https://github.com/idleray/prhttp","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"1e5ca45e145afcf622efee54c1d63d2a0c08d977"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idleray%2Fprhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idleray%2Fprhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idleray%2Fprhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idleray%2Fprhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idleray","download_url":"https://codeload.github.com/idleray/prhttp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312147,"owners_count":21082638,"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":["http","interceptor","javascript","lifecycle","nodejs"],"created_at":"2025-04-10T22:58:38.876Z","updated_at":"2025-04-10T22:58:40.137Z","avatar_url":"https://github.com/idleray.png","language":"JavaScript","readme":"# prhttp\nA JavaScript HTTP interceptor inspired by [okhttp](https://github.com/square/okhttp)\n\n## Installation\n```shell\nnpm install prhttp\n```\n\n## Usage\n### Create HTTP engine\nCreate an object which implement `execute` function\n```\nclass exampleEngine() {\n    execute(request) {\n        //execute http request\n    }\n}\n```\n### Create interceptor\nCreate an ojbect which implement `intercept` function\n```\nclass exampleInterceptor() {\n    async intercept(chain) {\n        const newRequest = chain.request.newRequest()\n        newRequest.setHeader('Authorization', 'your token')\n        return await chain.proceed(newRequest)\n    }\n}\n```\n### Send Http request\n```\nimport { PrHttpClientBuilder, PrRequestBuilder}  from 'prhttp'\n\nlet builder = new PrHttpClientBuilder()\nlet httpClient = builder.setEngine(new exampleEngine())\n                        .addInterceptor(new exampleInterceptor)\n                        .build()\n\nlet getBuilder = new PrRequestBuilder()\ngetBuilder.setMethod('get')\n              .setBaseUrl(\"https://www.example.com\")\n              .setContentType('application/json')\n\nlet request = getBuilder.build()\nconst data = {\n    data1: 'data'\n}\nrequest.setUrl('your api').setData(data)\n\nhttpClient.newCall(request).execute()\n```\n### Cancellation\nYou can cancel a request Using `Call.cancel()`. Instead of normal return , `CancelError` will be thrown.\n```\nconst call = httpClient.newCall(request)\ncall.execute().then(res =\u003e {\n    console.log(res)\n}).catch( e =\u003e {\n    if(e instanceof CancelError) {\n        console.log('Request was cancelled')\n    } else {\n        console.log(e)\n    }\n})\n\nsetTimeout( () =\u003e {\n    call.cancel()\n}, 100)\n```\n\n### Lifecycle Binding\n`PrHttpClient` instance can be bound to a lifecycle. When the state of lifecycle is `BEFORE_UNMOUNTED`, `Call.cancel()` will be call.\n\n- [React Binding](https://github.com/idleray/prhttp-react)\n- [Vue Binding](https://github.com/idleray/prhttp-vue)\n\n## Example\nYou can look at a [full example](example/index.js) which use [Axios](https://github.com/axios/axios) as engine","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidleray%2Fprhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidleray%2Fprhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidleray%2Fprhttp/lists"}