New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zodios/core

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zodios/core

Typescript API client with autocompletion and zod validations

  • 10.9.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @zodios/core?

@zodios/core is a TypeScript-first HTTP client library that provides a way to define and consume RESTful APIs with type safety. It leverages Zod for schema validation and TypeScript for type inference, ensuring that API requests and responses conform to expected types.

What are @zodios/core's main functionalities?

Define API Endpoints

This feature allows you to define API endpoints with type-safe request and response schemas using Zod. The code sample demonstrates defining a GET endpoint for '/users' with a response schema that expects an array of user objects.

const api = makeApi([{
  method: 'get',
  path: '/users',
  alias: 'getUsers',
  response: z.array(z.object({
    id: z.number(),
    name: z.string()
  }))
}]);

Type-safe API Requests

Once the API is defined, you can make type-safe requests using the Zodios client. The code sample shows how to make a request to the 'getUsers' endpoint, with TypeScript ensuring the response conforms to the expected type.

const client = new Zodios(api);
const users = await client.getUsers();

Error Handling with Zod

Zodios provides built-in error handling for schema validation errors. The code sample demonstrates catching a ZodiosError and accessing validation errors if the response does not match the expected schema.

try {
  const users = await client.getUsers();
} catch (error) {
  if (error instanceof ZodiosError) {
    console.error('Validation error:', error.errors);
  }
}

Other packages similar to @zodios/core

Keywords

FAQs

Package last updated on 22 Aug 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc