{"id":25627372,"url":"https://github.com/codex-central/mock-axios-request","last_synced_at":"2025-07-04T03:32:24.969Z","repository":{"id":213323121,"uuid":"733228415","full_name":"Codex-Central/mock-axios-request","owner":"Codex-Central","description":"Functions to allow test the request and responses in Axios format","archived":false,"fork":false,"pushed_at":"2023-12-21T23:16:49.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-27T23:49:24.819Z","etag":null,"topics":["axios","javascript","jest","mock","testing","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@codexcentral/mock-axios-request","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Codex-Central.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,"roadmap":null,"authors":null}},"created_at":"2023-12-18T21:18:01.000Z","updated_at":"2023-12-20T12:48:14.000Z","dependencies_parsed_at":"2024-01-08T12:14:51.468Z","dependency_job_id":null,"html_url":"https://github.com/Codex-Central/mock-axios-request","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"a4b54103848625280909deca120f042029cbf6aa"},"previous_names":["codex-central/mock-axios-request"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Codex-Central/mock-axios-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fmock-axios-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fmock-axios-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fmock-axios-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fmock-axios-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codex-Central","download_url":"https://codeload.github.com/Codex-Central/mock-axios-request/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fmock-axios-request/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263025586,"owners_count":23401804,"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":["axios","javascript","jest","mock","testing","typescript"],"created_at":"2025-02-22T17:48:13.441Z","updated_at":"2025-07-04T03:32:24.961Z","avatar_url":"https://github.com/Codex-Central.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MockAxiosRequest\nFunctions to allow test the request and responses in Axios format.\n\n## Installation\n\n\u003e `npm install @codexcentral/mock-axios-request`\n\n## Usage\n### 1. Importing and creating a new instance\n\n```javascript\nimport { MockApiClient, MockApiClientConfig } from '@codexcentral/mock-axios-request';\n\nconst baseUrl = 'https://example.com/api';\nconst mockApi = new MockApiClient(baseUrl);\n```\n\n \n### 2. Mocking a request\n#### GET\n\n```javascript\ntry {\n  const config: MockApiClientConfig = {\n    endpoint: '/users',\n    status: 200, // Change this for the status you want to test\n    response: [\n      { id: 1, name: 'User 1' },\n      { id: 2, name: 'User 2' },\n      { id: 3, name: 'User 3' },\n      { id: 4, name: 'User 4' },\n    ],\n  };\n  const data = await mockApi.get\u003c[{ id: string; name: string }]\u003e(config);\n  console.log('Data:', data);\n} catch (error) {\n  console.error('Error:', error);\n}\n```\n\n#### POST\n\n```javascript\ntry {\n  const config: MockApiClientConfig = {\n    endpoint: '/users/5',\n    status: 201, // Change this for the status you want to test\n    request: { name: 'User 5' },\n    response: { id: 5, name: 'User 5' },\n  };\n  const data = await mockApi.post\u003c{ id: string; name: string }\u003e(config);\n  console.log('Data:', data);\n} catch (error) {\n  console.error('Error:', error);\n}\n```\n\n#### PUT\n\n```javascript\ntry {\n  const config: MockApiClientConfig = {\n    endpoint: '/users/5',\n    status: 200, // Change this for the status you want to test\n    request: { name: 'User 5' },\n    response: { id: 5, name: 'User 5' },\n  };\n  const data = await mockApi.put\u003c{ id: string; name: string }\u003e(config);\n  console.log('Data:', data);\n} catch (error) {\n  console.error('Error:', error);\n}\n```\n\n#### DELETE\n\n```javascript\ntry {\n  const config: MockApiClientConfig = {\n    endpoint: '/users/5',\n    status: 200, // Change this for the status you want to test\n    response: { id: 5, name: 'User 5' },\n  };\n  const data = await mockApi.delete\u003c{ id: string; name: string }\u003e(config);\n  console.log('Data:', data);\n} catch (error) {\n  console.error('Error:', error);\n}\n```\n\n\n### MockApiClientConfig\n\n| Attribute | Type | Mandatory |\n| ------ | ------ | ------ |\n|  endpoint | `string` | true |\n|  status | `number` | true (100 to 599) |\n|  headers | `array` | false |\n|  response | `array` | false |\n|  response | `array` | false |\n|  delayResponse | `number` | false (default: 1000 - in milliseconds) |\n\n#### Example of MockApiClientConfig\n```json\n{\n  \"endpoint\": \"/users\",\n  \"status\": 200,\n  \"headers\": [],\n  \"response\": [],\n  \"response\": [],\n  \"delayResponse\": 1000\n}\n```\n\n# Credits\nThese code was written by [Roberto Silva Z.](https://www.linkedin.com/in/robertosilvazuniga/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-central%2Fmock-axios-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodex-central%2Fmock-axios-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-central%2Fmock-axios-request/lists"}