tyrann
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

tyrann

An easy solution to keep your REST calls and data types in the same place

Author

  • Chenyu Wang

    @hanayashiki is the current maintainer of the code and has written much of the current code base.

    Welcome to my technical blog (mostly in Simplified Chinese): https://blog.chenyu.pw

Overview

  • Describe your data
import { tyrann, yup } from "tyrann";
const api = {
    paths: {
        "/coordinate": {
            post: {
                body: yup.object({
                    x: yup.number().required(),
                    y: yup.number().required(),
                }),
                responses: {
                    '200': yup.object({
                        id: yup.number().required(),
                        outside_the_plane: yup.boolean(),
                    })
                }
            }
        },
        "/coordinate/{id}": {
            get: {
                path: yup.object({
                    id: yup.number().required(),
                }),
                responses: {
                    '200': yup.object({
                        x: yup.number().required(),
                        y: yup.number().required(),
                    })
                }
            }
        },
    }
};

const client = tyrann(api);
  • Ask for what you want
    const response = await client.fetch("get", "/coordinate/{id}", {
        pathParams: { id: 1 }
    })
  • Get predictable results
    console.log(response['200'])
    {
        "x": 114,
        "y": 514
    }

Readme

Keywords

none

Package Sidebar

Install

npm i tyrann

Weekly Downloads

1

Version

0.2.3

License

MIT

Unpacked Size

46.4 kB

Total Files

29

Last publish

Collaborators

  • chenyuwang