New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

laze-rest

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laze-rest

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

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

laze

A tiny typed class-based REST client based on ohmyfetch.

usage

// 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())

FAQs

Package last updated on 19 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc