Back to articles
Zodios Has a Free API — End-to-End Type-Safe REST Client with Zod
How-ToTools

Zodios Has a Free API — End-to-End Type-Safe REST Client with Zod

via Dev.to TutorialAlex Spinov

Zodios is a type-safe REST API client that uses Zod schemas. Define your API once with Zod schemas — get a fully typed client with autocompletion, runtime validation, and OpenAPI generation. Why Zodios? Zod-powered — same schema validates AND types Auto-completion — paths, params, body, response — all typed Runtime validation — responses validated against schema OpenAPI — generate docs from your definitions Quick Start npm install @zodios/core zod import { makeApi , Zodios } from ' @zodios/core ' ; import { z } from ' zod ' ; const userSchema = z . object ({ id : z . number (), name : z . string (), email : z . string (). email (), }); const api = makeApi ([ { method : ' get ' , path : ' /users ' , alias : ' getUsers ' , response : z . array ( userSchema ), }, { method : ' get ' , path : ' /users/:id ' , alias : ' getUser ' , response : userSchema , }, { method : ' post ' , path : ' /users ' , alias : ' createUser ' , parameters : [{ name : ' body ' , type : ' Body ' , schema : z . obj

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles