{"id":21147829,"url":"https://github.com/siamahnaf/next-fetcher","last_synced_at":"2026-01-31T10:31:49.580Z","repository":{"id":242857680,"uuid":"810698929","full_name":"siamahnaf/next-fetcher","owner":"siamahnaf","description":"A nextjs typescript friendly utility for seamless data fetching.","archived":false,"fork":false,"pushed_at":"2026-01-01T19:18:10.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-07T03:22:23.197Z","etag":null,"topics":["api","api-fetching","auto-fetching","cookie","cookies","data-fetching","js","next","next-fetcher","nextjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/next-fetcher?activeTab=readme","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/siamahnaf.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,"zenodo":null}},"created_at":"2024-06-05T07:41:37.000Z","updated_at":"2026-01-01T19:18:14.000Z","dependencies_parsed_at":"2024-11-20T09:43:24.178Z","dependency_job_id":"56ccd761-31bc-4ef0-9d9a-b502975512f6","html_url":"https://github.com/siamahnaf/next-fetcher","commit_stats":null,"previous_names":["siamahnaf/next-fetcher"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/siamahnaf/next-fetcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siamahnaf%2Fnext-fetcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siamahnaf%2Fnext-fetcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siamahnaf%2Fnext-fetcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siamahnaf%2Fnext-fetcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/siamahnaf","download_url":"https://codeload.github.com/siamahnaf/next-fetcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siamahnaf%2Fnext-fetcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28938565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T10:18:23.202Z","status":"ssl_error","status_checked_at":"2026-01-31T10:18:22.693Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["api","api-fetching","auto-fetching","cookie","cookies","data-fetching","js","next","next-fetcher","nextjs"],"created_at":"2024-11-20T09:18:46.603Z","updated_at":"2026-01-31T10:31:49.574Z","avatar_url":"https://github.com/siamahnaf.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/siamahnaf"],"categories":[],"sub_categories":[],"readme":"\u003cpicture\u003e\r\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/logo/logo-white.png\"\u003e\r\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/logo/logo-black.png\"\u003e\r\n  \u003cimg alt=\"Siam Ahnaf\" src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/logo/logo-black.png\" height=\"auto\" width=\"240\"\u003e\r\n\u003c/picture\u003e\r\n\r\n# Next Fetcher\r\n`next-fetcher` is a powerful, TypeScript-friendly utility for seamless data fetching in Next.js app router. It leverages Axios for HTTP requests, supports customizable request configurations, and provides robust error handling with optional `.throwOnError()` chaining. Simplify your client and server-side data fetching workflows with `next-fetcher.`\r\n\r\n** This utility only for nextjs app router. Page router do not support this package.\r\n\r\n\r\n\u003ca href=\"https://www.buymeacoffee.com/siamahnaf\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\r\n\r\n- Small in Size\r\n- All functionality\r\n- Zero config\r\n- Properly Maintained\r\n\r\n# Installation\r\n\r\n```bash\r\n$ npm i next-fetcher\r\n```\r\n\r\n## Server Components\r\n\r\n```bash\r\nimport { createServerFetcher } from \"next-fetcher\";\r\n\r\nconst Page = async () =\u003e {\r\n    const fetcher = createServerFetcher({ next: true, sessionName: \"token\" });\r\n    //It can be called outside of component. \r\n    //On that case you can import fetcher for use it in your component.\r\n\r\n    const data = await fetcher.get(\"/api\");\r\n\r\n    return (\r\n        \u003cdiv\u003e\r\n            {JSON.stringify(data)}\r\n        \u003c/div\u003e\r\n    );\r\n};\r\n\r\nexport default Page;\r\n```\r\n\r\n## API (Server Components)\r\n\u003ctable width=\"100%\"\u003e\r\n  \u003ctr\u003e\r\n    \u003cth\u003e Name \u003c/th\u003e\r\n    \u003cth\u003e Types \u003c/th\u003e\r\n    \u003cth\u003e Default \u003c/th\u003e\r\n    \u003cth\u003e Description \u003c/th\u003e\r\n  \u003c/tr\u003e\r\n  \u003ctr\u003e\r\n    \u003ctd\u003e next \u003c/td\u003e\r\n    \u003ctd\u003e Boolean (Required) \u003c/td\u003e\r\n    \u003ctd\u003e \u003c/td\u003e\r\n    \u003ctd\u003e Give `true` if you are using nextjs api. If you are using non-nextjs api then give this value as `false`. \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e baseURL \u003c/td\u003e\r\n    \u003ctd\u003e string (Required if `next` is `false`) \u003c/td\u003e\r\n    \u003ctd\u003e \u003c/td\u003e\r\n    \u003ctd\u003e Give the base url if you are not using nextjs api. \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e sessionName \u003c/td\u003e\r\n    \u003ctd\u003e string (Required if you do not provide `cookie`) \u003c/td\u003e\r\n    \u003ctd\u003e \u003c/td\u003e\r\n    \u003ctd\u003e The cookie name which one need to be sent for authorization \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e cookie \u003c/td\u003e\r\n    \u003ctd\u003e string (Required if you do not provide `sessionName`) \u003c/td\u003e\r\n    \u003ctd\u003e  \u003c/td\u003e\r\n    \u003ctd\u003e If you want to you can directly provide the cookie value \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e sessionOptions \u003c/td\u003e\r\n    \u003ctd\u003e Options (Optional) \u003c/td\u003e\r\n    \u003ctd\u003e  \u003c/td\u003e\r\n    \u003ctd\u003e Cookie options \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n## Client Components\r\n\r\n```bash\r\nimport { createClientFetcher, Fetcher } from \"next-fetcher\";\r\nimport { useQuery } from \"@tanstack/react-query\";\r\n\r\nconst GET_BOOKS = async(fetcher: Fetcher)=\u003e {\r\n  return fetcher.get(\"/api\")\r\n}\r\n\r\nconst Page = () =\u003e {\r\n  const fetcher = createClientFetcher({ next: true, sessionName: \"token\" });\r\n  //It can be called outside of component. \r\n  //On that case you can import fetcher for use it in your component.\r\n\r\n  //Using tanstack/react-query\r\n  const { data } = useQuery({ queryKey: [\"books\"], queryFn: () =\u003e GET_BOOKS(fetcher) })\r\n\r\n  return (\r\n    \u003cdiv\u003e\r\n      {JSON.stringify(data)}\r\n    \u003c/div\u003e\r\n  );\r\n};\r\n\r\nexport default Page;\r\n```\r\n\r\n## API (Client Components)\r\n\u003ctable width=\"100%\"\u003e\r\n  \u003ctr\u003e\r\n    \u003cth\u003e Name \u003c/th\u003e\r\n    \u003cth\u003e Types \u003c/th\u003e\r\n    \u003cth\u003e Default \u003c/th\u003e\r\n    \u003cth\u003e Description \u003c/th\u003e\r\n  \u003c/tr\u003e\r\n  \u003ctr\u003e\r\n    \u003ctd\u003e next \u003c/td\u003e\r\n    \u003ctd\u003e Boolean (Required) \u003c/td\u003e\r\n    \u003ctd\u003e \u003c/td\u003e\r\n    \u003ctd\u003e Give `true` if you are using nextjs api. If you are using non-nextjs api then give this value as `false`. \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e baseURL \u003c/td\u003e\r\n    \u003ctd\u003e string (Required if `next` is `false`) \u003c/td\u003e\r\n    \u003ctd\u003e \u003c/td\u003e\r\n    \u003ctd\u003e Give the base url if you are not using nextjs api. \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e sessionName \u003c/td\u003e\r\n    \u003ctd\u003e string (Required if you do not provide `cookie`) \u003c/td\u003e\r\n    \u003ctd\u003e \u003c/td\u003e\r\n    \u003ctd\u003e The cookie name which one need to be sent for authorization \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e cookie \u003c/td\u003e\r\n    \u003ctd\u003e string (Required if you do not provide `sessionName`) \u003c/td\u003e\r\n    \u003ctd\u003e  \u003c/td\u003e\r\n    \u003ctd\u003e If you want to you can directly provide the cookie value \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e sessionOptions \u003c/td\u003e\r\n    \u003ctd\u003e Options (Optional) \u003c/td\u003e\r\n    \u003ctd\u003e  \u003c/td\u003e\r\n    \u003ctd\u003e Cookie options \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n\r\n# Error Handling\r\n`next-fetcher` do not throwing any error during data fetching. But if you want to throw error you can use `throwOnError()` chaining method.\r\n\r\n-Example-\r\n\r\n```bash\r\nfetcher.get(\"/api\").throwOnError();\r\nfetcher.post(\"/api\").throwOnError();\r\nfetcher.put(\"/api\").throwOnError();\r\nfetcher.delete(\"/api\").throwOnError();\r\n```\r\n\r\n# Typescript Usage\r\n`next-fetcher` is typescript friendly. You can declare your response type like-\r\n\r\n```bash\r\nfetcher.get\u003cdata:any\u003e(\"/api\").throwOnError();\r\nfetcher.post\u003c{message:string}\u003e(\"/api\").throwOnError();\r\nfetcher.put\u003c{message:string}\u003e(\"/api\").throwOnError();\r\nfetcher.delete\u003c{message:string}\u003e(\"/api\").throwOnError();\r\n```\r\n\r\n# Cookie Management(Session)\r\n`next-fetcher` support cookie management system. You can add cookie or delete cookie using `next-fetcher` utility function.\r\n\r\n```bash\r\nimport { addSession, deleteSession } from \"next-fetcher\";\r\n\r\n//Add session (Adding cookie)\r\naddSession('key', 'value', options);\r\n\r\n//Delete Session (Removing cookie)\r\ndeleteSession('key', options);\r\n```\r\n\r\nNOTE! When deleting a cookie and you're not relying on the default attributes, you must pass the exact same path and domain attributes that were used to set the cookie:\r\n\r\n```bash\r\ndeleteSession('key', { path: '/path', domain: '.yourdomain.com' });\r\n```\r\n\r\n## API (Cookie Management)\r\n\u003ctable width=\"100%\"\u003e\r\n  \u003ctr\u003e\r\n    \u003cth\u003e Name \u003c/th\u003e\r\n    \u003cth\u003e Description \u003c/th\u003e\r\n  \u003c/tr\u003e\r\n  \u003ctr\u003e\r\n    \u003ctd\u003e key \u003c/td\u003e\r\n    \u003ctd\u003e Cookie's name \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n   \u003ctr\u003e\r\n    \u003ctd\u003e value \u003c/td\u003e\r\n    \u003ctd\u003e Cookie's value \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n  \u003ctr\u003e\r\n    \u003ctd\u003e options \u003c/td\u003e\r\n    \u003ctd\u003e Cookie's options like- `req`, `res`, `cookies`, `domain`, `encode`, `expires`, `httpOnly`,  `maxAge`,  and `path` \u003c/td\u003e\r\n  \u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n## Connect with me\r\n\u003cdiv style=\"display: flex; align-items: center; gap: 3px;\"\u003e\r\n\u003ca href=\"https://wa.me/8801611994403\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/whatsapp.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003ca href=\"https://siamahnaf.com/\" style=\"margin-right: 8px\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/web.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003ca href=\"https://www.linkedin.com/in/siamahnaf/\" style=\"margin-right: 8px\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/linkedin.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003ca href=\"https://x.com/siamahnaf198\" style=\"margin-right: 8px\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/x.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003ca href=\"https://www.facebook.com/siamahnaf198/\" style=\"margin-right: 8px\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/facebook.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003ca href=\"https://t.me/siamahnaf198\" style=\"margin-right: 8px\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/telegram.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003ca href=\"https://www.npmjs.com/~siamahnaf\" style=\"margin-right: 8px\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/siamahnaf/assets-kit/main/icons/npm.png\" width=\"40\" height=\"40\"\u003e\u003c/a\u003e\r\n\u003c/div\u003e\r\n\r\n\r\n------------\r\n\r\n\u003cp align=\"center\" color=\"red\"\u003e\u003ca href=\"https://www.siamahnaf.com/\"\u003ewww.siamahnaf.com\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiamahnaf%2Fnext-fetcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiamahnaf%2Fnext-fetcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiamahnaf%2Fnext-fetcher/lists"}