0.2.3 • Published 2 years ago

tyrann v0.2.3

Weekly downloads
127
License
MIT
Repository
github
Last release
2 years ago

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
    }
0.2.3

2 years ago

0.1.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.2

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago