{"id":19057642,"url":"https://github.com/pktcodes/axios-basics-v2","last_synced_at":"2026-04-17T09:31:15.006Z","repository":{"id":193759191,"uuid":"687826216","full_name":"pktcodes/axios-basics-v2","owner":"pktcodes","description":"Axios Basics using React","archived":false,"fork":false,"pushed_at":"2023-09-15T05:52:09.000Z","size":186,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-12T09:07:02.261Z","etag":null,"topics":["axios","create-react-app","custom-instance","get","global-defaults","headers","interceptors","javascript","john-smilga","netlify","post","react","request","response"],"latest_commit_sha":null,"homepage":"https://react-axios-basics-v2-prod.netlify.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pktcodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-09-06T04:55:25.000Z","updated_at":"2023-09-09T21:10:40.000Z","dependencies_parsed_at":"2023-09-09T21:20:06.682Z","dependency_job_id":"9b3b40df-fc0e-4f81-8f26-887e9b0fab5e","html_url":"https://github.com/pktcodes/axios-basics-v2","commit_stats":null,"previous_names":["praveen-1995/axios-basics-v2","pktcodes/axios-basics-v2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pktcodes/axios-basics-v2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pktcodes%2Faxios-basics-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pktcodes%2Faxios-basics-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pktcodes%2Faxios-basics-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pktcodes%2Faxios-basics-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pktcodes","download_url":"https://codeload.github.com/pktcodes/axios-basics-v2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pktcodes%2Faxios-basics-v2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31923067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T09:10:15.403Z","status":"ssl_error","status_checked_at":"2026-04-17T09:10:14.455Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","create-react-app","custom-instance","get","global-defaults","headers","interceptors","javascript","john-smilga","netlify","post","react","request","response"],"created_at":"2024-11-08T23:58:31.614Z","updated_at":"2026-04-17T09:31:14.978Z","avatar_url":"https://github.com/pktcodes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Axios\n\n#### Docs\n\n[Axios Docs](https://axios-http.com/docs/intro)\n\n#### Install\n\n```sh\nnpm install axios\n```\n\n```js\n\u003cscript src='https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js'\u003e\u003c/script\u003e\n```\n\n#### First Request\n\n- import axios\n\n- axios.get(url)\n- axios.post(url)\n- axios.patch/put(url)\n- axios.delete(url)\n\n- default get axios(url)\n\n- returns a promise\n- response data located in data property\n- error in error.response\n\n```js\nimport axios from 'axios';\n\nconst fetchData = async () =\u003e {\n  try {\n    // axios.get(), axios.post(),axios.put(), axios.delete()\n    const response = await axios(url);\n\n    console.log(response);\n  } catch (error) {\n    console.log(error.response);\n  }\n};\n```\n\n#### Headers\n\n- second argument\n- axios.get(url,{})\n\n- third argument in requests with data\n- axios.post(url,{data},{})\n\n```js\nconst fetchDadJoke = async () =\u003e {\n  try {\n    const { data } = await axios(url, {\n      headers: {\n        Accept: 'application/json',\n      },\n    });\n    // console.log(data);\n    setJoke(data.joke);\n  } catch (error) {\n    console.log(error.response);\n  }\n};\n```\n\n#### Post Request\n\n- send data to the server\n- axios.post(url, { data })\n- more options (auth header) - axios.post(url, { data },{})\n\n```js\ntry {\n  const resp = await axios.post(url, { data });\n} catch (error) {\n  console.log(error.response.data);\n}\n```\n\n#### Global Defaults\n\n```js\n// In latest axios version common property returns \"undefined\"\n// axios.defaults.headers.common['Accept'] = 'application/json';\naxios.defaults.headers['Accept'] = 'application/json';\n\naxios.defaults.baseURL = 'https://api.example.com';\n\n// In latest axios version common property returns \"undefined\"\n// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;\naxios.defaults.headers['Authorization'] = AUTH_TOKEN;\n\naxios.defaults.headers.post['Content-Type'] =\n  'application/x-www-form-urlencoded';\n```\n\n#### Custom Instance\n\n```js\nconst authFetch = axios.create({\n  baseURL: 'https://course-api.com',\n  headers: {\n    Accept: 'application/json',\n  },\n});\n```\n\n#### Interceptors\n\n- global and custom\n\n```js\nauthFetch.interceptors.request.use(\n  (request) =\u003e {\n    // request.headers.common['Accept'] = `application/json`;\n    request.headers['Accept'] = `application/json`;\n\n    console.log('request sent');\n    // must return request\n    return request;\n  },\n  (error) =\u003e {\n    return Promise.reject(error);\n  }\n);\n\nauthFetch.interceptors.response.use(\n  (response) =\u003e {\n    console.log('got response');\n    return response;\n  },\n  (error) =\u003e {\n    console.log(error.response);\n    if (error.response.status === 404) {\n      // do something\n      console.log('NOT FOUND');\n    }\n    return Promise.reject(error);\n  }\n);\n```\n\n##### Update\n\nIn the latest version there is no common property\n\n```js\n// In latest axios version common property returns \"undefined\"\n// axios.defaults.headers.common['Accept'] = 'application/json';\naxios.defaults.headers['Accept'] = 'application/json';\n\n// In latest axios version common property returns \"undefined\"\n// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;\naxios.defaults.headers['Authorization'] = AUTH_TOKEN;\n```\n\n```js\n// request.headers.common['Accept'] = `application/json`;\nrequest.headers['Accept'] = `application/json`;\n```\n\n---\n\n_Note: I have developed this project as part of React 18 Tutorial and Projects Course (2023) taught by John Smilga._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpktcodes%2Faxios-basics-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpktcodes%2Faxios-basics-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpktcodes%2Faxios-basics-v2/lists"}