1.0.0 • Published 5 months ago

phaster-api v1.0.0

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

Phaster API

Easily integrate with API endpoints built with Phaster.

Installation

npm install phaster-api

Usage

import { Endpoint, request } from "phaster-api";

The request function is a small wrapper around fetch which automatically parses JSON responses.

The Endpoint class simplifies requests to Phaster API endpoints:

const users = new Endpoint<User>("/api/users", request);

Each Endpoint instance has the following methods:

search(params: URLSearchParams): Promise<SearchResponse<T>>

Make a GET request to search entities.

getById(id: number | string): Promise<T>

Return a single entity by ID.

postAll(entities: T[]): Promise<T[]>

Create multiple entities with a single request. Returns the saved entities with their ID.

post(entity: T): Promise<T>

Create a single entity. Returns the saved entity with its ID.

put(entity: T): Promise<{ affected: number }>

Replace all writable properties on a single entity.

save(entity: T): Promise<T>

Automatically call post or put depending on whether the entity has an ID, and return the saved entity with its ID.

patch(id: number | string, patch: Partial<T>): Promise<{ affected: number }>

Update a subset of properties on one or more entities (pass a comma-separated list of IDs to update multiple rows).

delete(id: number | string): Promise<null>

Delete one or more entities (pass a comma-separated list of IDs to delete multiple rows).

1.0.0

5 months ago

0.9.1

8 months ago

0.9.0

8 months ago

0.8.4

8 months ago

0.8.3

9 months ago

0.8.2

9 months ago

0.8.1

9 months ago

0.8.0

9 months ago