# laze-rest

> A REST API client for Deno, node, and the browser

Latest version **0.3.0** (published 2021-12-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install laze-rest
pnpm add laze-rest
yarn add laze-rest
bun add laze-rest
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2021-12-19 |
| First published | 2021-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 34.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | tnt_man1671 |

## Links

- npm: https://www.npmjs.com/package/laze-rest
- Repository: https://github.com/suyashtnt/laze
- Homepage: https://github.com/suyashtnt/laze#readme
- Issues: https://github.com/suyashtnt/laze/issues
- npm.io page: https://npm.io/package/laze-rest

## Dependencies (3)

- [ohmyfetch](https://npm.io/package/ohmyfetch.md) v0.4.11
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) 6.2.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) 0.1.13

## Recent versions

- 0.3.0 (latest) — 2021-12-19
- 0.2.0 — 2021-12-19
- 0.1.2 — 2021-12-19
- 0.1.1 — 2021-12-19
- 0.1.0 — 2021-12-19

## README

# laze

A **tiny** typed class-based REST client based on [ohmyfetch](https://github.com/unjs/ohmyfetch).

## usage

```ts
// deno
import { ... } from "https://deno.land/x/laze@0.1.0/mod.ts"
// node/npm
// use this for react/vue/svelte/a bundler
import { ... } from "laze-rest"
// browser via skypack (get a pinned URL for production)
// https://docs.skypack.dev/skypack-cdn/api-reference/pinned-urls-optimized
import { ... } from "https://www.skypack.dev/laze-rest"
// browser bundle containing all dependencies + laze (only ~9kb)
import { ... } from "https://github.com/Suyashtnt/laze/releases/download/version/bundle.js"

// use your own api base path, typicode is the example
// NOTE: types are obviously for typescript only
// (why would you use this without typescript anyways?)
@RestClient("https://jsonplaceholder.typicode.com")
class TestClient {
  @GET("/todos")
  // laze automatically parses JSON for you into an object
  getAllTodos(): Promise<Todo[]> {
    // this gets replaced at runtime
    // this shouldn't:tm: be bad for performance
    throw new Error("not implemented");
  }

  @GET("/todos")
  // use a query for ?query=whatever
  getTodosForUser(@Query("userId") userId: number): Promise<Todo[]> {
    throw new Error("not implemented");
  }

  @POST("/todos")
  // bodies are automatically serialized using JSON
  addTodo(@Body todo: Omit<Todo, "id">): Promise<Pick<Todo, "id">> {
    throw new Error("not implemented");
  }

  // prefix a path variable with :
  @PUT("/todos/:id")
  replaceTodo(
    // and use an argument to give it a value
    @Path("id") todoId: number,
    @Body newTodo: Todo,
  ): Promise<Todo> {
    throw new Error("not implemented");
  }

  // Headers go before the method because of the way decorators work 
  @Header("Test", "Use wireshark or something to see it being sent")
  @PATCH("/todos/:id")
  updateTodo(
    @Path("id") _todoId: number,
    @Body _newTodo: Partial<Todo>,
  ): Promise<Todo> {
    throw new Error("not implemented");
  }

  @DELETE("/todos/:id")
  deleteTodo(@Path("id") _todoId: number): Promise<void> {
    throw new Error("not implemented");
  }
}

// create a client whenever you want to use it
const client = new TestClient();

// just use it like a method, supplying your arguments if needed
console.log(client.getAllTodos())
```

---
_Source: https://npm.io/package/laze-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
