Gathering detailed insights and metrics for axios-zod-gen
Gathering detailed insights and metrics for axios-zod-gen
Strongly-typed API functions with runtime validation based on Axios and Zod.
npm install axios-zod-gen
Typescript
Module System
Node Version
NPM Version
67.4
Supply Chain
90.5
Quality
83.9
Maintenance
100
Vulnerability
100
License
TypeScript (96.39%)
JavaScript (3.61%)
Total Downloads
491
Last Day
1
Last Week
6
Last Month
23
Last Year
491
1 Stars
58 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.4
Package Id
axios-zod-gen@0.1.4
Unpacked Size
28.20 kB
Size
5.51 kB
File Count
7
NPM Version
10.9.0
Node Version
20.16.0
Publised On
10 Dec 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
20%
6
Compared to previous week
Last month
-90.8%
23
Compared to previous month
Last year
0%
491
Compared to previous year
1
1
returnSchema
, the expected status code is 400. However, since the status code cannot be modified through Axios interceptors, the library is being deprecated.This package allows you to easily create strongly-typed API functions with runtime validation. Which is based on Axios and Zod
You can generate multiple API functions based on a configuration object by using initApiFunctions
.
This allows you to create a set of typed and validated API calls.
1import { initApiFunctions } from 'axios-zod-gen'; 2import { z } from 'zod'; 3 4const configs = { 5 getUser: { 6 method: 'get', 7 url: '/user/:id', 8 pathParamSchema: z.object({ id: z.string() }), 9 returnSchema: z.object({ id: z.string(), name: z.string() }), 10 }, 11 updateUser: { 12 method: 'post', 13 url: '/user/:id', 14 pathParamSchema: z.object({ id: z.string() }), 15 bodySchema: z.object({ name: z.string() }), 16 }, 17}; 18 19const api = initApiFunctions(configs); 20 21// Usage: 22async function fetchUser() { 23 const response = await api.getUser({ id: '123' }); 24 console.log(response.data); // { id: '123', name: 'John Doe' } 25} 26 27async function saveUser() { 28 const response = await api.updateUser({ id: '123', name: 'Jane Doe' }); 29 console.log(response.data); 30}
If you only need to create a single API function, you can use createApiFunction
directly.
1import { createApiFunction } from 'axios-zod-gen'; 2import { z } from 'zod'; 3 4const getUser = createApiFunction({ 5 method: 'get', 6 url: '/user/:id', 7 pathParamSchema: z.object({ id: z.string() }), 8 returnSchema: z.object({ id: z.string(), name: z.string() }), 9}); 10 11// Usage: 12const user = await getUser({ id: '123' }); 13console.log(user.data); // { id: '123', name: 'John Doe' }
This project is licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.