Minimal, type-safe REST client using JS proxies

Overview

uncreate

Minimal, type-safe REST client using JS proxies.

("https://jsonplaceholder.typicode.com"); // `GET` request to https://jsonplaceholder.typicode.com/users const allUsers = await api.users(); // Typed `GET` request to https://jsonplaceholder.typicode.com/users/1 const singeUser = await api.users (1);">
import { createApi } from "uncreate";

enum ApiEndpoints {
  Users = "users",
  Posts = "posts",
}

const api = createApi<ApiEndpoints>("https://jsonplaceholder.typicode.com");

// `GET` request to https://jsonplaceholder.typicode.com/users
const allUsers = await api.users();

// Typed `GET` request to https://jsonplaceholder.typicode.com/users/1
const singeUser = await api.users<ApiUserResponse>(1);

uncreate uses ohmyfetch for data fetching under the hood. Thus, every option available for ohmyfetch is usable with uncreate as well!

Installation

Run the following command to add uncreate to your project.

pnpm install uncreate # or npm or yarn

Configuration

", { // Complete list of options: https://github.com/unjs/ohmyfetch async onRequestError({ request, options, error }) { console.log("[fetch request error]", request, error); }, async onResponseError({ request, options, error }) { console.log("[fetch response error]", request, error); }, });">
import { createApi } from "uncreate";

const api = createApi("
   
    "
   , {
  // Complete list of options: https://github.com/unjs/ohmyfetch
  async onRequestError({ request, options, error }) {
    console.log("[fetch request error]", request, error);
  },
  async onResponseError({ request, options, error }) {
    console.log("[fetch response error]", request, error);
  },
});

License

MIT License © 2022 Johann Schopplich

You might also like...

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Apr 15, 2022

Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 🤟

Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 🤟

About routes-gen is a framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. Think of it as Prisma,

Jan 2, 2023

100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

Dec 29, 2022

JavaScript enums using proxies.

enum-xyz JavaScript enums using proxies. Based on this tweet Install $ npm install enum-xyz --save Usage Strings import Enum from 'enum-xyz' const {

Oct 22, 2022

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.

proxyquire Proxies nodejs's require in order to make overriding dependencies during testing easy while staying totally unobtrusive. If you want to stu

Dec 27, 2022

NodeJS library without any external dependencies to check if free HTTP/SOCKS4/SOCKS5 proxies are working/up

free-proxy_checker NodeJS library WITHOUT any external dependencies to: download free proxies; check if free HTTP/SOCKS4/SOCKS5 proxies are working/up

Nov 6, 2022

🚀 A Node.js server that automaticaly finds and checks proxies for you.

🚀 A Node.js server that automaticaly finds and checks proxies for you.

Proxi A Node.js app that automaticaly finds and checks proxies for you and shows them on a dashboard. Install & Setup ## Download git clone https://gi

Jul 7, 2022

Generate type definitions compatible with @kintone/rest-api-client

Generate type definitions compatible with @kintone/rest-api-client

kintone-form-model-generator Generate type definitions compatible with @kintone/rest-api-client Prerequirements Node.js (=12) Install # Install npm i

Dec 15, 2022

🪱 Zorm - Type-safe form for React using Zod

React Zorm Type-safe form for React using Zod! Features / opinions 💎 Type-safe Get form data as a typed object Typo-safe name and id attribute gene

Dec 25, 2022

A fully type-safe and lightweight way of using exceptions instead of throwing errors

🛡️ exceptionally A fully type-safe and lightweight way of using exceptions instead of throwing errors 🦺 fully typesafe 🐤 lightweight (209 bytes) 🏃

Jan 4, 2023

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Jul 19, 2022

Fast and type-safe full stack framework, for TypeScript

Fast and type-safe full stack framework, for TypeScript

Fast and type-safe full stack framework, for TypeScript Why frourio ? Even if you write both the frontend and backend in TypeScript, you can't statica

Dec 26, 2022

Micro type-safe wrapper for Node.js AMQP library and RabbitMQ management.

Micro type-safe wrapper for AMQP library and RabbitMQ management Description Section in progress. Getting Started Qupi can be installed by Yarn or NPM

Oct 5, 2021

Type-Safe Errors for JS & TypeScript

Type-Safe Errors for JS & TypeScript

Jan 6, 2023

Build type-safe web apps with PureScript.

Build type-safe web apps with PureScript.

PUX Build type-safe web applications with PureScript. Documentation | Examples | Chat Pux is a PureScript library for building web applications. Inter

Jun 18, 2022

graphql-codegen plugin to generate type-safe, easy-to use hooks for Flutter

graphql-codegen-flutter-artemis-hooks This is graphql-codegen plugin to generate type-safe, easy-to use Flutter artemis hooks. For further detail, see

Jan 2, 2023

A zero-dependency, buildless, terse, and type-safe way to write HTML in JavaScript.

hdot A sensible way to write HTML in JavaScript. Type-safe. Helps you follow the HTML spec. Terse. Almost character for character with plain HTML. Bui

Oct 24, 2022

Type Safe Object Notation & Validation

tson Type Safe Object Notation & Validation 📌 Work in Progress, not ready for production... Features 🧱 Functional 🔷 Immutable ✅ Well tested Why? Af

Aug 10, 2022

Cloudy is a set of constructs for the AWS Cloud Development Kit that aim to improve the DX by providing a faster and type-safe code environment.

cloudy-ts These packages aren't yet published on npm. This is still highly experimental. Need to figure out a few things before releasing the first ve

Nov 3, 2022
Releases(v0.9.3)
Owner
Johann Schopplich
Web designer/developer. Pharmacist prior to that.
Johann Schopplich
HTTP Client for Visual Studio Code to POST JSON, XML, image, ... files to REST APIs

friflo POST Goal Main goal of this extension is storing all HTTP request & response data automatically as files in a VSCode workspace. This ensures th

Ullrich Praetz 2 Nov 18, 2021
Get a full fake REST API with zero coding in less than 30 seconds (seriously)

JSON Server Get a full fake REST API with zero coding in less than 30 seconds (seriously) Created with <3 for front-end developers who need a quick ba

null 64.9k Jan 3, 2023
Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

axios 98k Dec 31, 2022
🏊🏾 Simplified HTTP request client.

Deprecated! As of Feb 11th 2020, request is fully deprecated. No new changes are expected to land. In fact, none have landed for some time. For more i

request 25.6k Jan 4, 2023
Ajax for Node.js and browsers (JS HTTP client)

superagent Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features T

Sloth 16.2k Jan 1, 2023
HTTP Client Utilities

@hapi/wreck HTTP client utilities. wreck is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other c

hapi.js 383 Nov 1, 2022
Very very very powerful, extensible http client for both node.js and browser.

ES-Fetch-API 中文 | English Very very very powerful, extensible http client for both node.js and browser. Why should you use ES-Fetch API? Still using a

null 17 Dec 12, 2022
Global HTTP/HTTPS proxy agent configurable using environment variables.

global-agent Global HTTP/HTTPS proxy configurable using environment variables. Usage Setup proxy using global-agent/bootstrap Setup proxy using bootst

Gajus Kuizinas 267 Dec 20, 2022
A DEV.to clone using MERN stack

DEV.to Clone An DEV.to clone created with MongoDB, Express, React, and Socket.io Live Site Backend API Tech UI: React Routing: React Router Real-time

Eknoorpreet Singh 328 Dec 9, 2022
Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Titanium Network 27 Jan 2, 2023