npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hyqo/nanoapi

v0.1.0

Published

A lightweight, type-safe API client for SvelteKit applications that leverages native SvelteKit features.

Downloads

8

Readme

@hyqo/nanoapi

A lightweight, type-safe API client for SvelteKit applications that leverages native SvelteKit features.

Features

  • SvelteKit-native: Uses SvelteKit's fetch and error handling
  • Type-safe: TypeScript support with Success and Failure types
  • Lightweight: Minimal dependencies
  • Flexible: Configurable base URL and request options
  • Helper utilities: Built-in query params, body, and method helpers

Installation

npm install @hyqo/nanoapi

Usage

Creating an API client

// src/lib/api.server.ts
import { createApiClient } from '@hyqo/nanoapi'

export const api = createApiClient({
    base: 'https://api.example.com',
    prepareRequest: init => {
        // Add default headers, authentication, etc.
        init.headers = {
            ...init.headers,
            Authorization: 'Bearer token',
        }
    },
})

Making requests

// +page.server.ts
import { api } from '$lib/api.server'
import { withQuery, withMethod, withBody } from '@hyqo/nanoapi'

export async function load() {
    // GET request
    const users = await api('/users', withMethod('GET'))

    // GET with query parameters
    const filteredUsers = await api(`/users${withQuery({ role: 'admin', active: true })}`, withMethod('GET'))

    return { users, filteredUsers }
}

export const actions = {
    create: async ({ request }) => {
        const data = await request.formData()

        // POST request with JSON body
        const result = await api('/users', {
            ...withBody('POST'),
            body: JSON.stringify({
                name: data.get('name'),
                email: data.get('email'),
            }),
        })

        return result
    },
}

API Reference

createApiClient(options)

Creates a new API client instance.

Parameters:

  • options.base (string): Base URL for all requests (defaults to empty string)
  • options.prepareRequest (function, optional): Function to modify RequestInit before each request

Returns: An async function (path: string, init?: RequestInit) => Promise<unknown>

Helper Functions

withQuery(query)

Converts an object to URL query parameters.

withQuery({ search: 'test', page: 1 })
// Returns: "?search=test&page=1"

withBody(method, contentType)

Creates RequestInit object for requests with body.

withBody('POST', 'application/json')
// Returns: { method: 'POST', headers: { 'Content-Type': 'application/json' } }

Default: method = 'POST', contentType = 'application/json'

withMethod(method)

Creates RequestInit object with HTTP method.

withMethod('GET')
// Returns: { method: 'GET' }

Types

type Success<T extends object = {}> = Promise<{ ok: true } & T>
type Failure<T extends object = {}> = Promise<{ ok: false } & T>

Use these types for type-safe API responses:

async function getUser(id: string): Success<{ user: User }> | Failure<{ error: string }> {
    // ...
}

Error Handling

The client automatically handles HTTP errors:

  • 2xx: Returns parsed JSON
  • 4xx: Returns parsed JSON (client errors)
  • 5xx: Throws SvelteKit error using error(status)

Development

npm install
npm run dev

Building

npm run build

Testing

npm test

License

MIT