![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@navios/navios-zod-react
Advanced tools
Navios Zod React
is a helper for a navios zod to use with Tanstack React Query.
Developers forget to use zod
to check the data before using it. This can lead to unexpected errors in the application. Navios Zod
provides a simple way to check the data before using it.
You cannot trust that API will return the data in the format you expect. Navios Zod
provides a simple way to check the data before using it.
npm install --save @navios/navios-zod zod navios
or
yarn add @navios/navios-zod zod navios
import { z } from 'zod'
import { createAPI } from '@navios/navios-zod'
const API = createAPI({
baseURL: 'https://example.com/api/',
})
const GetUserResponseSchema = z.object({
id: z.number(),
name: z.string(),
})
const getUser = API.get({
user: 'user',
responseSchema: GetUserResponseSchema,
})
Or more complex example with request schema:
import { z } from 'zod'
import { declareAPI } from '@navios/navios-zod'
import { GetUsersResponseSchema } from './schemas/GetUsersResponseSchema.js'
const API = declareAPI({
useDiscriminatorResponse: true,
useWholeResponse: true,
})
const UpdateUserRequestSchema = z.object({
id: z.number(),
name: z.string(),
})
const UpdateUserResponseSchema = z.discriminatedUnion('status', [
z.object({
status: z.literal(200),
data: GetUsersResponseSchema,
}),
z.object({
status: z.literal(400),
data: z.object({
error: z.string(),
}),
}),
])
const updateUser = API.put({
url: 'user/$userId',
requestSchema: UpdateUserRequestSchema,
responseSchema: UpdateUserResponseSchema,
})
// In another file you can set the API client
const client = create({
baseURL: 'https://example.com/api/',
headers: {
Authorization: 'Bearer token',
},
})
API.provideClient(client)
// Usage
const { data: updatedUserOrError, status } = await updateUser({
urlParams: {
userId: 1,
},
data: {
id: 1,
name: 'John Doe',
},
})
if (status === 200) {
console.log(updatedUserOrError)
} else {
console.error(updatedUserOrError)
}
declareAPI
declareAPI
is a function that creates an API object. It accepts an object with the following properties:
useDiscriminatorResponse
- if true
, the error response will be checked by the original responseSchema. Default is false
.useWholeResponse
- if true
, the whole response will be checked. Default is false
.The function returns an API object with the following methods:
declareEndpoint
- creates an endpoint with the specified options.declareEndpoint({
method: 'get' | 'post' | 'put' | 'delete' | 'patch',
url: string,
requestSchema?: z.ZodSchema<unknown>, // Only for POST, PUT, PATCH methods
responseSchema: z.ZodSchema<unknown>,
querySchema?: z.ZodSchema<unknown>,
})
provideClient
- sets the client for the API.provideClient(client: Navios)
get
, post
, put
, delete
, patch
, options
- creates an endpoint with the specified options.API.get({
url: string,
responseSchema: z.ZodSchema<unknown>,
querySchema?: z.ZodSchema<unknown>,
})
createAPI
createAPI
is a wrapper around declareAPI
that creates an API object with default navios client.
const API = createAPI({
baseURL: string,
useDiscriminatorResponse?: boolean,
useWholeResponse?: boolean,
})
The function returns an API object with the same methods as declareAPI
.
FAQs
Unknown package
The npm package @navios/navios-zod-react receives a total of 17 weekly downloads. As such, @navios/navios-zod-react popularity was classified as not popular.
We found that @navios/navios-zod-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.