1.1.3-b • Published 2 years ago

@patrick115/endpoints v1.1.3-b

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Endpoints

Small library for creating endpoints and executing fetch requests to them using Zod type safety.

Usage

import { Endpoint } from "@patrick115/endpoints"
import z from "zod"

//schema for the response
const schema = z.object({
    status: z.literal(true),
    data: z.object({
        id: z.number(),
        name: z.string(),
    })
})

//creating endpoint
const endpoint = new Endpoint("/api/path/to/endpoint", "POST", {
    username: "patrick115",
    password: "example123",
}, schema)

//fetch endpoint and return Promise, that can be fullfilled with our data, or rejected with error
endpoint.fetch()

/*
fetch endpoint and return object
{
    status: true,
    data: {
        id: 1,
        name: "patrick115"
    }
}
or if api sends error, which match error schema, it will return
{
    status: true,
    errorSchema: true,
    data: {
        //error from api
        status: false,
        error: "Invalid password"
    }
}
or if fetch fails
{
    status: false,
    error: "Text error" // or error can be object
}
*/
endpoint.fetchSafe()
1.1.3-b

2 years ago

1.1.3-a

2 years ago

1.1.3

2 years ago

1.1.2-e

2 years ago

1.1.2-d

2 years ago

1.1.2-c

2 years ago

1.1.2-b

2 years ago

1.1.2-a

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago