{"id":24755145,"url":"https://github.com/gravity-ui/axios-wrapper","last_synced_at":"2025-10-11T01:31:26.947Z","repository":{"id":42450291,"uuid":"433751153","full_name":"gravity-ui/axios-wrapper","owner":"gravity-ui","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-20T08:53:59.000Z","size":604,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-01-22T11:46:09.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/gravity-ui.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-01T08:53:40.000Z","updated_at":"2025-01-20T08:54:00.000Z","dependencies_parsed_at":"2024-08-22T09:50:36.884Z","dependency_job_id":null,"html_url":"https://github.com/gravity-ui/axios-wrapper","commit_stats":null,"previous_names":["yandex-cloud/axios-wrapper"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Faxios-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Faxios-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Faxios-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-ui%2Faxios-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gravity-ui","download_url":"https://codeload.github.com/gravity-ui/axios-wrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236017656,"owners_count":19081961,"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":"2025-01-28T12:36:29.937Z","updated_at":"2025-10-11T01:31:21.665Z","avatar_url":"https://github.com/gravity-ui.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Axios Wrapper\nThis library provides a convenient wrapper around Axios adding automatic cancelling of concurrent requests\nto its features.\n\n## Install\n\n```shell\nnpm install --save-dev @gravity-ui/axios-wrapper\n```\n\n## HTTP API\n\n### Constructor parameters\n\n##### config [optional]\nThe configuration of an `axios` instance.\n\n##### collector [optional]\nThe configuration of requests collector is an object:\n```json\n{\n    \"collectErrors\": 10,\n    \"collectRequests\": 10\n}\n```\n\n### Basic methods\nWrapper provides http-methods `get`, `head`, `put`, `post`, `delete`.\n\nMethods `get` and `head` have the signature `(url, params, options)`; `put`, `post`, while the `delete` method\nhas `(url, data, params, options)` signature.\n\nThe `params` argument stands for query string parameters while `options` is a request settings.\n\nCurrently 4 request settings are supported:\n- `concurrentId (string)`: optional request id\n- `collectRequest (bool)`: optional flag, telling if the request should be logger (default `true`)\n- `requestConfig (object)`: optional config with the custom request parameters\n- `headers (object)`: optional object with custom request headers.\n- `timeout (number)`: optional request timeout\n- `onDownloadProgress (function)`: optional callback for processing file download progress\n\n### Headers\nThe `setDefaultHeader({name (string), value (string), methods (array)})` method allows to add a default\nrequest header.\n\nArguments `name` and `value` are required, optional argument `methods` specified all methods which get those\ndefault headers (by default all methods will get those headers).\n\n### CSRF\nThe `setCSRFToken` method allows specifying CSRF-token, which will be added to all `put`, `post` and `delete`\nrequests.\n\n### Concurrent requests\nSometimes it is better to cancel the request in flight if its results are no longer needed. To make this\nhappen, one should pass to request's `options` the `concurrentId` id. When the next request with the same\n`concurrentId` occurs the previous request with that id will be cancelled.\n\nOne cancel a request manually as well by invoking the `cancelRequest(concurrentId)` method.\n\n### Collecting requests\nIt is possible to set up requests collection into the local storage using the `collector` option. It stores\nall requests and errors separately. The following `apiInstance` will keep 10 last requests (both successful\nand not) and 10 last erroneous requests.\n```javascript\nconst apiInstance = new API({\n    collector: {\n        collectErrors: 10,\n        collectRequests: 10\n    }\n});\n```\n\nTo obtain saved requests one have to invoke the `getCollectedRequests` method which returns the object\n`{errors: [...], requests: [...]}`.\n\n### Usage\nThe suggested usage is to subclass the base `AxiosWrapper` class:\n```javascript\nexport class API extends AxiosWrapper {\n    getProjects() {\n        return this.get('/projects');\n    }\n    getSensors({project, selectors}) {\n        return this.get(`/projects/${project}/sensors`, {selectors, pageSize: 200});\n    }\n    getNames({project, selectors}) {\n        return this.get(`/projects/${project}/sensors/names`, {selectors});\n    }\n    getLabels({project, names, selectors}) {\n        return this.get(`/projects/${project}/sensors/labels`, {names, selectors});\n    }\n}\n```\n\nWhen the `baseURL` parameter is passed into `axios` config, all requested pathnames will be appended to it.\n```javascript\nconst apiInstance = new API({\n    config: {\n        baseURL: '/api/v2'\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravity-ui%2Faxios-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgravity-ui%2Faxios-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravity-ui%2Faxios-wrapper/lists"}