{"id":13990856,"url":"https://github.com/renancaraujo/axios-endpoints","last_synced_at":"2025-04-15T12:37:52.037Z","repository":{"id":32585802,"uuid":"137011397","full_name":"renancaraujo/axios-endpoints","owner":"renancaraujo","description":"Axios endpoints helps you to create a more concise endpoint mapping with axios. ","archived":false,"fork":false,"pushed_at":"2024-07-09T16:50:14.000Z","size":2395,"stargazers_count":42,"open_issues_count":9,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-28T20:21:18.878Z","etag":null,"topics":["ajax","api","endpoints","fetch","fetch-api","hacktoberfest","javascript"],"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/renancaraujo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-12T03:20:40.000Z","updated_at":"2024-05-10T21:24:07.000Z","dependencies_parsed_at":"2024-01-18T05:18:05.033Z","dependency_job_id":"e385510c-7aec-4048-9981-925ceae055a2","html_url":"https://github.com/renancaraujo/axios-endpoints","commit_stats":{"total_commits":268,"total_committers":9,"mean_commits":29.77777777777778,"dds":"0.40671641791044777","last_synced_commit":"65786258e90ff700bb99ecb127013ac7aec0eb9c"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renancaraujo%2Faxios-endpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renancaraujo%2Faxios-endpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renancaraujo%2Faxios-endpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renancaraujo%2Faxios-endpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renancaraujo","download_url":"https://codeload.github.com/renancaraujo/axios-endpoints/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249072827,"owners_count":21208253,"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":["ajax","api","endpoints","fetch","fetch-api","hacktoberfest","javascript"],"created_at":"2024-08-09T13:03:24.610Z","updated_at":"2025-04-15T12:37:52.014Z","avatar_url":"https://github.com/renancaraujo.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Axios endpoints\n\n[![Build Status](https://travis-ci.org/renancaraujo/axios-endpoints.svg?branch=master)](https://travis-ci.org/renancaraujo/axios-endpoints)\n[![npm](https://img.shields.io/npm/v/axios-endpoints.svg)](https://www.npmjs.com/package/axios-endpoints)\n\nAxios endpoints helps you to create a more concise endpoint mapping with a simple but flexible api. It is as wrapper over [axios](https://github.com/axios/axios).\n\n### Getting started\n\nBefore anything, install axios-endpoints\n\n```bash\nnpm install --save axios #axios is a peer dependency\nnpm install --save axios-endpoints\n```\n\n### Usage with Factory (recommended)\n\nFor a more complete usage of axios settings, you may use the Factory. \n\n```javascript\nimport axios from \"axios\";\nimport EndpointFactory from \"axios-endpoints\";\n\nconst axiosInstance = axios.create({\n    baseURL: \"https://localhost:8080/api\"\n});\n\nconst Endpoint = EndpointFactory(axiosInstance);\n\nconst cityEndpoint = new Endpoint(\"/city\"); // GET https://localhost:8080/api/city\nconst postEndpoint = new Endpoint(({id = \"\"}) =\u003e \"/post/\" + id);\n\n// Header changing example\nfunction setAuthorization(MYTOKEN){\n  axiosInstance.defaults.headers.common[\"Authorization\"] = MYTOKEN;\n}\n\n\n\nfunction getCityList(callback) {\n   cityEndpoint.get().then(response=\u003e{\n      callback(response.data);\n   }).catch(e=\u003e{\n      console.log(\"That didnt go well\");\n   });\n}\n\n// do you like async stuff? so take this async example\nasync function getCityList(){\n   try{\n      const { data } = await cityEndpoint.get();\n      return data;\n   } catch (e) {\n      console.log(\"That didnt go well\");\n   }\n}\n\n\n```\n\n\n### Usage without factory\n\nThe fastest way to use axios-endpoints. ideal when you dont want to set any axios configs:\n\n```javascript\n// endpoints.js\nimport { Endpoint } from \"axios-endpoints\";\n\nexport const userEndpoint = new Endpoint(\"https://localhost:8080/api/user\");\n\n\n// anotherfile.js\nimport { userEndpoint } from \"./endpoints\";\n\nasync function getUserList(){\n   try{\n      const { data } = await userEndpoint.get();\n      return data;\n   } catch (e) {\n      console.log(\"That didnt go well\");\n   }\n}\n\n\n```\n\n### HTTP methods\n\nYou can user either `.get`  `.post`  `.put` and `.delete` as well:\n\n```javascript\n\nconst cityEndpoint = new Endpoint(\"/city\");\n\nconst { data } = await cityEndpoint.get(); // GET https://localhost:8080/api/city\nconst { data } = await cityEndpoint.get({\n    params: {country:\"brazil\"}\n}); // GET https://localhost:8080/api/city?country=brazil\n\n\nconst { data } = await cityEndpoint.post({\n   name: \"Hortolandia\", \n   country: \"Brazil\", \n   hazardLevel: 10000\n}, {\n  params: { someParam: \"icecream\" }\n}); \n/*\ncurl --request POST \\  \n  --url https://localhost:8080/api/city?someParam=icecream \\\n  --header 'Content-Type: application/json' \\\n  --data '{\n   \"name\": \"Hortolandia\", \n   \"country\": \"Brazil\", \n   \"hazardLevel\": 10000\n  }'\n*/\n```\n\n\n#### uriParams\n\nNot always your endpoint will be represented by a fixed string. For that, uri params exists.\n\n```javascript\nconst postEndpoint = new Endpoint(({postId = \"\"}) =\u003e \"/post/\" + postId)\n\nconst { data } = await postEndpoint.get({\n   uriParams: {\n      postId: 1\n   }\n}); // GET https://localhost:8080/api/post/1\n```\n\nFor more information about parameters and returned values, check the API section.\n\n\n\n## API\n\n#### `EndpointFactory`\n```javascript\nimport axios from \"axios\";\nimport EndpointFactory from \"axios-endpoints\"\n\nconst axiosInstance = axios.create(config);\nconst Enpoint = EndpointFactory(axiosInstance);\n```\n\nType: function\n\n| Parameters    |                |\n|---------------|----------------|\n| axiosInstance | Axios instance |\n\n`axiosInstance` is generated via `axios.create` function. For more information, check [axios documentation](https://github.com/axios/axios#axioscreateconfig).\n\nReturn: `Endpoint`\n\n\n#### `Endpoint`\n```javascript\nimport axios from \"axios\";\nimport EndpointFactory from \"axios-endpoints\"\n\nconst axiosInstance = axios.create(config);\nconst Enpoint = EndpointFactory(axiosInstance);\n```\nType: class\n\n##### Constructor\n\n| Constructor Parameters    | Type |\n|---------------|----------------|\n| endpointIdentifier | `String` or `Function any =\u003e String` |\n\n##### Instance methods\n\n###### `endpoint#get(options)`\n###### `endpoint#post(payload, options)`\n###### `endpoint#put(payload, options)`\n###### `endpoint#patch(payload, options)`\n###### `endpoint#delete(options)`\n\n| Parameters    | Type     |\n|---------------|----------------|\n| options | The same object as the [Request Config](https://github.com/axios/axios#request-config) with the extra property `uriParams`. \u003cbr /\u003e You may use  `params` and `uriParams` more often.|\n| payload | The object that will be carried as json payload of the request |\n\n\n\n\n## Contributing\n\nIf you got so far reading this README, you are maybe thinking about contributing. Pull requests are welcome.\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenancaraujo%2Faxios-endpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenancaraujo%2Faxios-endpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenancaraujo%2Faxios-endpoints/lists"}