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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@popsink/jsonapi-client

v1.4.4

Published

Simple jsonapi client.

Downloads

9

Readme

Popsink Json API client

Queries and deserializes JsonAPI responses using the power of typescript.

About The Project

This client uses Axios with the typing power of Typescript to construct requests to APIs using JSON:API.

Features

  • Build low-level queries. Maintain flexibility and a visual understanding of the JSON:API specification
  • Save time by using typing to create queries and retrieve JSON:API data.
  • Take advantage of automatic deserialization of your query returns, to retrieve objects that are easy to handle.

Why not use X or Y library already available?

There are already many frontend clients for consuming APIs using JSON:API. But none gave me complete satisfaction:

  • Most libraries return objects and their relationships with the JSON:API structure like User.attributes.projects.attributes.name. This way of manipulating data is too cumbersome and moves away from simple OOP use.
  • Some libraries are too complicated to handle.
  • Others are not flexible enough when creating queries.
  • Finally, others are absolutely not typed.

Getting started

Install the client using a package manager : npm install --save @popsink/jsonapi-client

Usage

Import and instanciate the JsonApiService.

import JsonApiService from '@popsink/jsonapi-client'
const api = new JsonApiService({ baseURL: 'https://myservice.com' })

Use the availables methods :

// Let's assume that the API returns users such as:
type TUser = {
    username: string
    nickname: string
}

// List the users
api.list<TUser>('users/').then((users) => {
    for (const user of users) {
        console.log(user.username) // { id: 1, username: 'Tomy', nickname: 'Tom' }
    }
})

// Get a user
api.get<TUser>('users/12/').then((user) => {
    console.log(user.username) // { id: 1, username: 'Tomy', nickname: 'Tom' }
})

// Create a user
api.create<TUser>('users/', {
    data: {
        type: 'user',
        attributes: {
            username: 'john',
            nickname: 'foo'
        }
    }
})

// Update a user
api.update<TUser>('users/', {
    data: {
        type: `users/12/`,
        attributes: {
            nickname: 'bar'
        }
    }
})

// Delete a user
api.remove('users/12/')

// Use low level request
api.request( ... )