@hulla/api

Welcome to the documentation of @hulla/api.

If you’re ready to dive in and don’t need motivation or comparisons with similar packages, feel free to head straight to the Installation page!

About

What is it?

What is it not?

Comparison

Functionality@hulla/api@trpcaxiossuperagent
Bundle size (minified)1.2 KB31 KB52 KB138 KB
Framework agnostic
Type-safe
Server actions
Requests
Procedures
Integrations/Adapters
Middleware
Interceptors
Native
Dependencies0039
Learning curve (subjective)MediumHardMediumEasy

- Last updated: 25.5.2024

Motivation

Fetching has been a challenge for the longest time in JavaScript. Entire languages and frameworks have been built primarily to improve handling and organization of calls. Over the past decade, we’ve made huge strides towards API management with tools like axios, which helped immensely but was too large and lacked type safety.

Then came @trpc, which addressed most of my issues with axios. For a while, it was the perfect solution. However, technology always progresses, and with the advent of server components and actions, trpc has become less compatible (through no fault of its own). Making it work with server actions and the client has become a headache.

When creating this package, I set the following goals:

Caveat: Package size

You might call it boasting, but size matters! At least when it comes to your JavaScript bundles. 😅

So, how is the package size so drastically different when it claims to do as much as similar tools?

  1. Advanced type inference: We let the types (0 KB when served to the client) do the heavy lifting instead of the JavaScript.
  2. Minimalist philosophy: The package avoids “Swiss-army knife” approaches that aim to do too much and must be bundled even though you don’t need them 90% of the time. The goal was to keep it minimal but extensible.
  3. No special “package-isms”: It doesn’t override behavior. It’s just pure TypeScript built on top of Functions and Promises. How you define your procedures is up to you.

For full disclosure, the core of @hulla/api doesn’t provide any “extra fetching logic,” which is part of both trpc and axios. As mentioned in the motivation section, one of my goals was to make the package minimal but extensible. You can still make fetch calls with just procedures, but if you want to be truly pedantic, the recommended integration for requests@hulla/api-request comes in at a whopping 1.3 KB. So even with that included (2.5 KB combined), it’s still 95.19% smaller than axios and 91.94% smaller than trpc.