{"id":18421192,"url":"https://github.com/brybrophy/axios-core-api","last_synced_at":"2025-04-07T14:31:38.656Z","repository":{"id":26342361,"uuid":"108225303","full_name":"brybrophy/axios-core-api","owner":"brybrophy","description":"Generate an Axios instance with business logic for all HTTP request methods.","archived":false,"fork":false,"pushed_at":"2024-10-12T22:25:44.000Z","size":154,"stargazers_count":8,"open_issues_count":4,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T19:43:12.660Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/brybrophy.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}},"created_at":"2017-10-25T05:47:36.000Z","updated_at":"2024-10-12T22:23:52.000Z","dependencies_parsed_at":"2023-01-14T04:27:33.010Z","dependency_job_id":null,"html_url":"https://github.com/brybrophy/axios-core-api","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Faxios-core-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Faxios-core-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Faxios-core-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Faxios-core-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brybrophy","download_url":"https://codeload.github.com/brybrophy/axios-core-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247669883,"owners_count":20976465,"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-06T04:24:41.502Z","updated_at":"2025-04-07T14:31:38.650Z","avatar_url":"https://github.com/brybrophy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Axios Core Api\n\n![https://img.shields.io/github/license/brybrophy/axios-core-api?color=blue](https://img.shields.io/github/license/brybrophy/axios-core-api?color=blue) ![https://img.shields.io/npm/v/axios-core-api](https://img.shields.io/npm/v/axios-core-api) ![https://img.shields.io/bundlephobia/minzip/axios-core-api](https://img.shields.io/bundlephobia/minzip/axios-core-api) ![https://img.shields.io/librariesio/release/npm/axios-core-api](https://img.shields.io/librariesio/release/npm/axios-core-api) ![https://img.shields.io/badge/tests-passing-brightgreen.svg](https://img.shields.io/badge/tests-passing-brightgreen.svg)\n\n### Generate an Axios instance with business logic for all HTTP request methods.\n\nThis package can be used to create a core api class to route requests between a client and an api.\n\nIt is written in TypeScript, and typings are included directly in the package.\n\n## Getting Started\n\n`yarn add axios-core-api` or `npm install axios-core-api`\n\n## Usage\n\nYou can read an in depth article on why and how to uses this package [on medium](https://medium.com/hello-high-seas/axios-core-api-object-oriented-javascript-love-effb37f14cd0).\n\n```javascript\nimport ApiCore from \"axios-core-api\";\n\nconst apiConfig = {\n  headers: {\n    Accept: \"application/json\",\n    Authorization: `Bearer 123abc`,\n    \"Content-Type\": \"application/json\",\n  },\n  timeout: 15000,\n};\n\nexport default class CrudApi {\n  constructor() {\n    this._apiCore = new ApiCore(apiConfig);\n    this._basePath = \"https://www.crud.org/api\";\n  }\n}\n```\n\n## Usage With TypeScript\n\n```javascript\nimport { AxiosRequestConfig } from \"axios\";\nimport ApiCore from \"axios-core-api\";\n\nconst apiConfig: AxiosRequestConfig = {\n  headers: {\n    Accept: \"application/json\",\n    Authorization: `Bearer 123abc`,\n    \"Content-Type\": \"application/json\",\n  },\n  timeout: 15000,\n};\n\nexport default class CrudApi {\n  _apiCore: ApiCore;\n  _basePath: string;\n\n  constructor() {\n    this._apiCore = new ApiCore(apiConfig);\n    this._basePath = \"https://www.crud.org/api\";\n  }\n}\n```\n\n## Methods\n\n### Get\n\n```javascript\ngetAll() {\n    return this._apiCore.get(`${this._basePath}`);\n}\n\ngetOne(id) {\n    return this._apiCore.get(`${this._basePath}/${id}`);\n}\n```\n\n### Post\n\n```javascript\ncreate(newExample) {\n    return this._apiCore.post(`${this._basePath}`, newExample);\n}\n```\n\n### Post Form Data\n\n```javascript\ncreateForm(newExample) {\n    return this._apiCore.postFormData(`${this._basePath}`, newExample);\n}\n```\n\n### Put\n\n```javascript\nupdatePut(id, nextExample) {\n    return this._apiCore.put(`${this._basePath}/${id}`, nextExample);\n}\n```\n\n### Patch\n\n```javascript\nupdatePatch(id, nextExample) {\n    return this._apiCore.patch(`${this._basePath}/${id}`, nextExample);\n}\n```\n\n### Delete\n\n```javascript\ndestroy(id) {\n    return this._apiCore.delete(`${this._basePath}/$id`);\n}\n```\n\n### refreshApiInstance\n\n```javascript\nrefreshApiInstance(newAccessToken) {\n    const newConfig = apiConfig;\n\n    newConfig.headers.Authorization = `Bearer ${newAccessToken}`;\n\n    this._apiCore.refreshApiInstance(newConfig);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrybrophy%2Faxios-core-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrybrophy%2Faxios-core-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrybrophy%2Faxios-core-api/lists"}