New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@koj/svelte-api-client

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koj/svelte-api-client

Koj's Fetch-powered API client for webapps

latest
Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

🥅 Koj Svelte API Client

This repository contains Koj's Fetch API-powered client for interacting with our API. It is very opinionated, so usage is only recommended in Koj's Svelte projects.

Status
BuildNode CI Dependencies GitHub release (latest by date) Snyk Vulnerabilities for GitHub Repo
HealthCLA Assistant Pull Request Labeler
PRsPR Generator CI Merge PRs

⭐️ Features

  • Wrapper around the native Fetch API (95%+ support)
  • Tracks logged in users and their permissions
  • Authorization helper can based on logged in scopes
  • Built-in refreshing expired access tokens before requests
  • Response caching in IndexedDB or local storage
  • Error handling (text responses from error codes)
  • Supports different request/responses:
    • Responses can be JSON or Blob objects
    • Requests can be JSON or FormData

💻 Getting started

Install the dependency from npm:

npm install @koj/svelte-api-client

Import the api method and use it like so:

import { api } from "@koj/svelte-api-client";
import type { User } from "@koj/types";

let user: User | undefined = undefined;
const getUser = async () => {
  user = await api<User>({
    method: "GET",
    url: "/users/12345",
    onCachedResponse: (data) => (user = data),
  });
};

In the above example, the api method expects a type parameter which determines its response time. Note that JSON responses are automatically parsed. The onCachedResponse function is used to get a "faster" responses from a client side-stored cache, using the stale-while-revalidate pattern.

📄 License

MIT © Koj

Koj

An open source project by Koj.
Furnish your home in style, for as low as CHF175/month →

Keywords

koj

FAQs

Package last updated on 24 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts