Skip to content

pnsk-lab/scratchapis

Repository files navigation

ScratchAPIs

ScratchAPIs provides a way to interact with the Scratch API used by the Scratch website with TypeScript.

Installation

This package is available on JSR.

bunx jsr add --bun @pnsk-lab/scratchapis # bun
deno add jsr:@pnsk-lab/scratchapis # deno
pnpm dlx jsr add --pnpm @pnsk-lab/scratchapis # pnpm
yarn dlx jsr add --yarn @pnsk-lab/scratchapis # yarn
npx jsr add @pnsk-lab/scratchapis # npm

Usage

This package provides high-level APIs and low-level APIs to interact with the Scratch API.

Low-level APIs

Low-level APIs is just a fetcher that has a TypeScript type for the request and response.

import { createFetcher } from '@pnsk-lab/scratchapis'

const client = createFetcher()

await client('GET https://api.scratch.mit.edu/users/:userId/messages/count', {
  params: {
    userId: 'ScratchCat',
  },
}).then(res => res.json()) // { count: number }

High-level APIs

High-level APIs are designed to be easy for tree-shaking.

import { createFetcher } from '@pnsk-lab/scratchapis'
import { getUserInfo } from '@pnsk-lab/scratchapis/users'

const client = createFetcher()
const userInfo = await getUserInfo(client, 'ScratchCat')
console.log(userInfo) // { id: string, username: string, ... }

Releases

No releases published

Packages

No packages published