1.1.3-b • Published 5 months ago

@patrick115/endpoints v1.1.3-b

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months 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

5 months ago

1.1.3-a

5 months ago

1.1.3

5 months ago

1.1.2-e

6 months ago

1.1.2-d

6 months ago

1.1.2-c

6 months ago

1.1.2-b

6 months ago

1.1.2-a

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago