Skip to content

Getting started

Corgi is built to be tiny by default, but has plugins to add support for additional use-cases.

All plugins are opt-in, so you can keep your bundle size small and only include what you need.

Install

sh
npm i @itsy/corgi
sh
pnpm add @itsy/corgi
sh
bun add @itsy/corgi
sh
deno add npm:@itsy/corgi

One-off requests

The corgi singleton can be used out of the box for simple requests where plugin-support isn't needed.

ts
import { 
corgi
} from '@itsy/corgi';
interface User {
id
: number;
name
: string;
} // GET + JSON parse + throw-on-error, typed as User const
user
= await
corgi
.
get
<User>('https://api.example.com/users/1');

It supports all HTTP methods as either a function or an option

ts
await 
corgi
.
head
('https://api.example.com/ping');
ts
await 
corgi
('https://api.example.com/ping', {
method
: 'HEAD' });

Configured clients

Use corgi.create() when you want shared defaults (base URL, headers, etc.) or Plugins that enable request timeouts, retries, and more.

ts
import { 
corgi
} from '@itsy/corgi';
const
api
=
corgi
.
create
({
baseURL
: 'https://api.example.com',
headers
: {
authorization
: 'Bearer token' },
}); const
users
= await
api
.
get
('/users'); // -> https://api.example.com/users

Batteries included

You can also get a batteries-included version of corgi from @itsy/corgi/chonk that includes all plugins!

Released under the MIT License.