1.3.9 • Published 6 months ago

http-wizard v1.3.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Full documentation website:

http-wizard.vercel.app

Introduction

Http-wizard weaves TypeScript magic, offering a type-safe API client and ensuring a delightful end-to-end developer experience. ✨

Here is an exemple of usage

https://github.com/flodlc/http-wizard/assets/3781663/71c749f0-3493-4865-8a9a-41421a371a05

What it can do:

  • Export a type-safe client API
  • Validate input and output of your routes
  • Drastically simplify your codebase and ensure validation best practices
  • Allow HTTP standards-compliant route naming and usage, with or without http-wizard as a client.

Table of Contents:


Installation

To get started, install http-wizard using npm or yarn:

npm install http-wizard
# or
yarn add http-wizard

Usage

Currently http-wizard uses Zod or Typebox for validation. Here is an exemple with Zod.

Let's first create a route on the server:

// server.ts
import { createRoute, z } from "http-wizard";

const User = z.object({
  id: z.string(),
  name: z.string(),
});

export const getUsers = (fastify: FastifyInstance) => {
  return createRoute("/users", {
    method: "GET",
    schema: {
      response: {
        200: z.array(User),
      },
    },
  }).handle((props) => {
    fastify.route({
      ...props,
      handler: (request) => {
        const users = await db.getUsers();
        return users;
      },
    });
  });
};

const router = { ...getUsers() };
export type Router = typeof router;

Now, let's use the Router type on the client:

// client.ts
import { createClient } from "http-wizard";
import axios from "axios";

import type { Router } from "./server";

const apiClient = createClient<Router>(axios.instance());
const users = await apiClient.ref("[GET]/users").query({});
// users array is safe: { id:string, name:string }[]

Easy right ?

1.3.9

6 months ago

1.3.9-beta.20

6 months ago

1.3.9-beta.19

6 months ago

1.3.9-beta.18

6 months ago

1.3.9-beta.17

6 months ago

1.3.9-beta.16

6 months ago

1.3.9-beta.15

6 months ago

1.3.9-beta.14

6 months ago

1.3.9-beta.13

6 months ago

1.3.9-beta.12

6 months ago

1.3.9-beta.10

6 months ago

1.3.9-beta.9

6 months ago

1.3.9-beta.8

6 months ago

1.3.9-beta.7

6 months ago

1.3.9-beta.6

6 months ago

1.3.9-beta.5

6 months ago

1.3.9-beta.4

6 months ago

1.3.9-beta.3

6 months ago

1.3.9-beta.2

6 months ago

1.3.9-beta.1

6 months ago

1.3.9-beta.0

6 months ago

1.3.8

6 months ago

1.3.7

6 months ago

1.3.6

6 months ago

1.3.5

6 months ago

1.3.4

7 months ago

1.3.3

7 months ago

1.3.2

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago

1.1.14

7 months ago

1.1.13

7 months ago

1.1.13-beta.0

7 months ago

1.1.12

7 months ago

1.1.12-beta.2

7 months ago

1.1.12-beta.1

7 months ago

1.1.12-beta.0

7 months ago

1.1.11

7 months ago

1.1.10

7 months ago