react-api-kit 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ A lightweight, production-ready API client built on **Axios** + **TanStack Query
9
9
  ✔ Custom static headers per project
10
10
  ✔ Global error handling with toast support
11
11
  ✔ Auto logout on 401
12
- ✔ React Query–ready hooks (GET, POST, PATCH, DELETE)
12
+ ✔ React Query–ready hooks (GET, POST, PUT, PATCH, DELETE)
13
13
  ✔ No UI dependencies — works with any toast library
14
14
 
15
15
  ---
@@ -208,7 +208,7 @@ function UserList() {
208
208
  ```ts
209
209
  const { mutate, mutateAsync, isPending, isError } = useApiMutation(
210
210
  mutationKey, // unique key array
211
- method, // "POST" | "PATCH" | "DELETE" | "GET"
211
+ method, // "POST" | "PUT" | "PATCH" | "DELETE" | "GET"
212
212
  invalidateKey? // query keys to refetch after success (optional)
213
213
  );
214
214
  ```
@@ -238,7 +238,18 @@ const handleCreate = () => {
238
238
  };
239
239
  ```
240
240
 
241
- #### PATCHUpdate
241
+ #### PUTFull Replace
242
+
243
+ ```tsx
244
+ const { mutate } = useApiMutation(["replaceUser"], "PUT", ["users"]);
245
+
246
+ mutate({
247
+ endpoint: `/users/${id}`,
248
+ data: { name: "John", email: "john@example.com", role: "admin" },
249
+ });
250
+ ```
251
+
252
+ #### PATCH — Partial Update
242
253
 
243
254
  ```tsx
244
255
  const { mutate } = useApiMutation(["updateUser"], "PATCH", ["users"]);
@@ -304,6 +315,9 @@ const res = await api.get("/orders", { params: { status: "pending" } });
304
315
  // POST
305
316
  const res = await api.post("/users", { name: "John" });
306
317
 
318
+ // PUT
319
+ const res = await api.put(`/users/${id}`, { name: "John", email: "john@example.com" });
320
+
307
321
  // PATCH
308
322
  const res = await api.patch(`/users/${id}`, { name: "Updated" });
309
323
 
@@ -356,7 +370,7 @@ src/
356
370
  ├── api/
357
371
  │ ├── axios.ts → Axios instance + request interceptor (auth + headers)
358
372
  │ ├── interceptors.ts → Response interceptor (error handling + auto logout)
359
- │ └── globalApi.ts → GET / POST / PATCH / DELETE wrappers
373
+ │ └── globalApi.ts → GET / POST / PUT / PATCH / DELETE wrappers
360
374
  └── hooks/
361
375
  ├── useApiQuery.ts → useQuery wrapper
362
376
  └── useApiMutation.ts → useMutation wrapper
@@ -33,6 +33,7 @@ a.interceptors.response.use(
33
33
  const u = {
34
34
  GET: (e, t) => a.get(e, { params: t }).then((s) => s.data),
35
35
  POST: (e, t) => a.post(e, t).then((s) => s.data),
36
+ PUT: (e, t) => a.put(e, t).then((s) => s.data),
36
37
  PATCH: (e, t) => a.patch(e, t).then((s) => s.data),
37
38
  DELETE: (e) => a.delete(e).then((t) => t.data)
38
39
  };
@@ -1 +1 @@
1
- (function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("axios"),require("@tanstack/react-query")):typeof define=="function"&&define.amd?define(["exports","axios","@tanstack/react-query"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o.ReactApiKit={},o.axios,o.reactQuery))})(this,(function(o,i,u){"use strict";let n;const p=e=>{n=e},a=i.create();a.interceptors.request.use(e=>{n?.baseURL&&(e.baseURL=n.baseURL),n?.headers&&Object.entries(n.headers).forEach(([s,r])=>{e.headers[s]=r});const t=n?.getToken?.();if(t){const s=n?.tokenType??"Bearer";e.headers.Authorization=`${s} ${t}`}return e}),a.interceptors.response.use(e=>(n?.onSuccess?.(e.data),e),e=>{const t=e?.response?.status,s={400:"Bad request. Please check your input.",401:"Session expired. Please login again.",403:"You do not have permission to perform this action.",404:"Requested resource not found.",409:"Conflict occurred. Please try again.",422:"Validation error. Please check the form.",500:"Server error. Please try again later."},r=e?.response?.data?.message||t&&n?.errorMessages?.[t]||t&&s[t]||e?.message||"Network Error";return n?.toast?.error(r,n.toastOptions),n?.onError?.(e,r),t===401&&n?.onLogout?.(),Promise.reject(e)});const d={GET:(e,t)=>a.get(e,{params:t}).then(s=>s.data),POST:(e,t)=>a.post(e,t).then(s=>s.data),PATCH:(e,t)=>a.patch(e,t).then(s=>s.data),DELETE:e=>a.delete(e).then(t=>t.data)};function f(e,t,s,r,c){return u.useQuery({queryKey:e,queryFn:()=>d[t](s,r),...c})}function h(e,t,s){const r=u.useQueryClient();return u.useMutation({mutationKey:e,mutationFn:({endpoint:c,data:l})=>d[t](c,l),onSuccess:()=>{s&&r.invalidateQueries({queryKey:s})}})}o.api=a,o.setupApi=p,o.useApiMutation=h,o.useApiQuery=f,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("axios"),require("@tanstack/react-query")):typeof define=="function"&&define.amd?define(["exports","axios","@tanstack/react-query"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.ReactApiKit={},a.axios,a.reactQuery))})(this,(function(a,i,u){"use strict";let n;const p=e=>{n=e},o=i.create();o.interceptors.request.use(e=>{n?.baseURL&&(e.baseURL=n.baseURL),n?.headers&&Object.entries(n.headers).forEach(([s,r])=>{e.headers[s]=r});const t=n?.getToken?.();if(t){const s=n?.tokenType??"Bearer";e.headers.Authorization=`${s} ${t}`}return e}),o.interceptors.response.use(e=>(n?.onSuccess?.(e.data),e),e=>{const t=e?.response?.status,s={400:"Bad request. Please check your input.",401:"Session expired. Please login again.",403:"You do not have permission to perform this action.",404:"Requested resource not found.",409:"Conflict occurred. Please try again.",422:"Validation error. Please check the form.",500:"Server error. Please try again later."},r=e?.response?.data?.message||t&&n?.errorMessages?.[t]||t&&s[t]||e?.message||"Network Error";return n?.toast?.error(r,n.toastOptions),n?.onError?.(e,r),t===401&&n?.onLogout?.(),Promise.reject(e)});const d={GET:(e,t)=>o.get(e,{params:t}).then(s=>s.data),POST:(e,t)=>o.post(e,t).then(s=>s.data),PUT:(e,t)=>o.put(e,t).then(s=>s.data),PATCH:(e,t)=>o.patch(e,t).then(s=>s.data),DELETE:e=>o.delete(e).then(t=>t.data)};function f(e,t,s,r,c){return u.useQuery({queryKey:e,queryFn:()=>d[t](s,r),...c})}function h(e,t,s){const r=u.useQueryClient();return u.useMutation({mutationKey:e,mutationFn:({endpoint:c,data:l})=>d[t](c,l),onSuccess:()=>{s&&r.invalidateQueries({queryKey:s})}})}a.api=o,a.setupApi=p,a.useApiMutation=h,a.useApiQuery=f,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-api-kit",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Reusable Axios + TanStack Query API hooks for React",
5
5
  "license": "ISC",
6
6
  "author": "Ajay kammar",
@@ -28,4 +28,4 @@
28
28
  "@vitejs/plugin-react": "^5.1.2",
29
29
  "vite": "^7.3.0"
30
30
  }
31
- }
31
+ }