@spa-tools
API Client
![Code Coverage](https://github.com/rollercodester/spa-tools/raw/HEAD/./coverage-badge.svg)
The @spa-tools/api-client
package excels in calling HTTP API endpoints with features specifically designed
for modern, data-driven web applications.
If your SPA has data workflows requiring calls to backend APIs
(public and/or private), then this tool may be just what the doctor ordered.
Feature highlights include:
- Throttling
- Caching
- State Interpolation
- Result Mapping
- React (or not)
- TypeScript First
- Zero Dependencies
- Tree-shakable
Quickstart
It's highly advised to first checkout the @spa-tools documentation site for a complete list of features, usage scenarios, guidance, and reference.
Installation
npm install @spa-tools/api-client
Usage
import { callEndpoint } from '@spa-tools/api-client';
export interface AlbumPhoto {
albumId: number;
id: number;
title: string;
url: string;
thumbnailUrl: string;
}
export async function getAlbumPhotos(albumId: number) {
const result = await callEndpoint<AlbumPhoto[]>(
'https://jsonplaceholder.typicode.com/albums/:albumId/photos',
{ albumId }
);
return result;
}
const albumId = 1;
const result = await getAlbumPhotos(albumId);
if (result.data) {
console.log(`Photos for album with ID "${albumId}":`);
console.log(result.data);
} else if (result.error) {
console.error(`Error retrieving photos for album with ID "${albumId}":`);
console.error(result.error);
}
Docsite
View the @spa-tools documentation site for complete reference.
Contributing
If you're interested in contributing to @spa-tools, please first create an issue on the @spa-tools monorepo in GitHub
or comment on an already open issue. From there we can discuss the feature or bugfix you're interested in and how best to approach it.
Unit Test Coverage
All packages in @spa-tools require 100% unit test coverage. This is a condition for all PRs to be merged whether you're adding a new feature or fixing a bug.
License
All packages in @spa-tools are licensed under the MIT license. Copyright © 2024, Ryan Howard (rollercodester). All rights reserved.