{"id":23799460,"url":"https://github.com/singularit-de/drf-axios-middleware","last_synced_at":"2025-09-06T13:32:52.882Z","repository":{"id":105034377,"uuid":"589466319","full_name":"singularit-de/drf-axios-middleware","owner":"singularit-de","description":"@singularit/drf-axios-middleware is a middleware for axios. It can be used with axios and django rest framework. It introduces a new parameter `filterSet` to the axios request config.","archived":false,"fork":false,"pushed_at":"2023-11-30T12:23:38.000Z","size":363,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-02T06:28:48.431Z","etag":null,"topics":["axios","axios-interceptor","axios-middleware","django","django-rest-framework","jest","singularit","typescript"],"latest_commit_sha":null,"homepage":"https://singularit-de.github.io/drf-axios-middleware/","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/singularit-de.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":"2023-01-16T07:26:11.000Z","updated_at":"2024-09-11T13:08:43.000Z","dependencies_parsed_at":"2023-11-16T08:47:54.123Z","dependency_job_id":null,"html_url":"https://github.com/singularit-de/drf-axios-middleware","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/singularit-de/drf-axios-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singularit-de%2Fdrf-axios-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singularit-de%2Fdrf-axios-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singularit-de%2Fdrf-axios-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singularit-de%2Fdrf-axios-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/singularit-de","download_url":"https://codeload.github.com/singularit-de/drf-axios-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singularit-de%2Fdrf-axios-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273912608,"owners_count":25189969,"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-09-06T02:00:13.247Z","response_time":2576,"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":["axios","axios-interceptor","axios-middleware","django","django-rest-framework","jest","singularit","typescript"],"created_at":"2025-01-01T21:16:36.956Z","updated_at":"2025-09-06T13:32:52.445Z","avatar_url":"https://github.com/singularit-de.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DRF-Axios-Middleware\n\n\u003ca href=\"https://www.npmjs.com/package/@singularit/drf-axios-middleware\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/@singularit/drf-axios-middleware?color=50a36f\u0026label=\" alt=\"NPM Downloads\"\u003e\n\u003c/a\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.singular-it.de/\"\u003e\n    \u003cpicture\u003e\n      \u003csource media=\"(prefers-color-scheme: dark)\"  srcset=\"./documents/singular_it_dark.png\"\u003e\n      \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"./documents/singular_it_light.png\"\u003e\n      \u003cimg width=\"500px\" alt=\"singularIT Logo\" src=\"./documents/singular_it_light.png\"\u003e\n    \u003c/picture\u003e    \n  \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.singular-it.de/\"\u003eWebsite\u003c/a\u003e |\n  \u003ca href=\"https://blog.singular-it.de/\"\u003eBlog\u003c/a\u003e |\n  \u003ca href=\"https://www.singular-it.de/team\"\u003eTeam\u003c/a\u003e\n\u003c/p\u003e\n\n## Features\n\n- 🦾 TypeScript support\n- 📦 CommonJS and ES Module support\n- ⚙️ Works with Axios and Django Rest Framework\n- 📝 Customizable\n- 📚 Well documented ([Docs](https://singularit-de.github.io/drf-axios-middleware/))\n\n## Installation\n\n```bash\nnpm install @singularit/drf-axios-middleware\n```\n\n## Usage\n\n### Basic\n\n`@singularit/drf-axios-middleware` is a middleware for axios. It can be used with axios and django rest framework. It\nintroduces a new parameter `filterSet` to the axios request config. This parameter is used to filter the request url.\nThe filterSet is a object with the following structure:\n\n```\n{\n  [field]: {\n    [operator]: value\n  }\n}\n```\n\nBy default, the operator can be one of the following:\n\n```ts\nconst DefaultDRFFilters = ['in', 'exact', 'lt', 'gt', 'lte', 'gte', 'startswith', 'endswith']\n```\n\nYou can use custom operators. See [Customization](#customization) for more information.\n\nThe final request url will be generated like: `url?field__operator=value`.\nFields can be nested and will be generated like: `url?field__nested__operator=value`.\nSee [Nested Fields](#nested-fields) for more information.\n\n#### Example\n\n```ts\nimport axios from 'axios';\nimport applyDrfMiddleware from '@singularit/drf-axios-middleware';\n\nconst api = applyDrfMiddleware(axios.create());\n\n// get all users with id \u003e= 15\napi.get('/api/v1/users/', {filterSet: {id: {gte: 15}}}).then((response) =\u003e {\n    console.log(response.data);\n});\n// request: GET /api/v1/users/?id__gte=15\n```\n\n### Nested Fields\n\nNested fields can be used to filter nested objects. The middleware will generate the correct url for you.\n\n#### Examples\n\n##### Basic Nested Field\n\n```ts\nimport axios from 'axios';\nimport applyDrfMiddleware from '@singularit/drf-axios-middleware';\n\nconst api = applyDrfMiddleware(axios.create());\n\n// get all users with id \u003e= 15\napi.get('/api/v1/users/', {filterSet: {profile: {id: {gte: 15}}}}).then((response) =\u003e {\n    console.log(response.data);\n});\n\n// request: GET /api/v1/users/?profile__id__gte=15\n```\n\n##### Nested Field with multiple operators\n\n```ts\nimport axios from 'axios';\nimport applyDrfMiddleware from '@singularit/drf-axios-middleware';\n\nconst api = applyDrfMiddleware(axios.create());\n\n// get all users with id \u003e= 15 and id \u003c= 99\napi.get('/api/v1/users/', {filterSet: {profile: {id: {gte: 15, lte: 99}}}}).then((response) =\u003e {\n    console.log(response.data);\n});\n\n// request: GET /api/v1/users/?profile__id__gte=15\u0026profile__id__lte=99\n```\n\n### Customization\n\nThe middleware can be customized by passing a config object to the `applyDrfMiddleware` function.\n\n#### Examples\n\n##### Custom Filter Handler\n\n```ts\nimport axios from 'axios';\nimport applyDrfMiddleware from '@singularit/drf-axios-middleware';\n\nconst api = applyDrfMiddleware(axios.create(), {\n    filterHanlder: {\n        notIn: (key, value) =\u003e {\n            return [{key: 'notin', value: value}]\n        }\n    }\n});\n\n// get all users with id not 1, 2 or 3 \napi.get('/api/v1/users/', {filterSet: {id: {notIn: [1, 2, 3]}}}).then((response) =\u003e {\n    console.log(response.data);\n});\n\n// request: GET /api/v1/users/?id__notin=1,2,3 \n// Note: depends on your array serializer\n```\n\n*Note:* `notin` is not a valid operator for django rest framework. You have to implement the filter on your own.\n\n##### Custom Filter to multiple Parameters (between to gte and lte)\n\n```ts\nimport axios from 'axios';\nimport applyDrfMiddleware from '@singularit/drf-axios-middleware';\n\nconst api = applyDrfMiddleware(axios.create(), {\n    filterHanlder: {\n        between: (key, value) =\u003e {\n            return [\n                {key: 'gte', value: value[0]},\n                {key: 'lte', value: value[1]}\n            ]\n        }\n    }\n});\n\n// get all users with id between 1 and 99\napi.get('/api/v1/users/', {filterSet: {id: {between: [1, 99]}}}).then((response) =\u003e {\n    console.log(response.data);\n});\n\n// request: GET /api/v1/users/?id__gte=1\u0026id__lte=99\n```\n\n## License\n\n[MIT License](./LICENSE) © 2023-PRESENT singularIT GmbH\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsingularit-de%2Fdrf-axios-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsingularit-de%2Fdrf-axios-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsingularit-de%2Fdrf-axios-middleware/lists"}