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

@haddowg/json-api-angular

v1.5.2

Published

Signal-based Angular bindings for the JSON:API client: an HttpClient transport, DI providers, resource/mutation helpers, and a TanStack Query entry point.

Readme

@haddowg/json-api-angular

Part of the jsonapi.rest suite — a complete, spec-compliant JSON:API 1.1 stack: a framework-agnostic PHP core, a Symfony bundle, a Laravel package, and this typed TypeScript client, bound together by one conformance-tested OpenAPI 3.1 contract. Full documentation: haddowg.github.io/json-api-ts.

Signal-based Angular bindings for a generated @haddowg/json-api-client. The client goes into dependency injection and sends through Angular's HttpClient, so your interceptors run on every request. Reads become signals through Angular's resource(), and writes get a small signal-based mutation handle.

Install

npm install @haddowg/json-api-angular @haddowg/json-api-client

@angular/core and @angular/common (20, 21 or 22) are peer dependencies.

Provide the client

import { provideHttpClient, withInterceptors } from '@angular/common/http'
import { provideJsonApiClient } from '@haddowg/json-api-angular'
import { createClient } from './api/music.gen'

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(withInterceptors([authInterceptor])),
    provideJsonApiClient(createClient, { baseUrl: '/api/v5' }),
  ],
}

Register the client's type once so it is typed everywhere without a token:

import type { JsonApiClientOf } from '@haddowg/json-api-angular'

declare module '@haddowg/json-api-angular' {
  interface Register {
    client: JsonApiClientOf<typeof createClient>
  }
}

For a second client (another server), create a token with createJsonApiClientToken() and pass it as the third argument to provideJsonApiClient, then to injectJsonApiClient(token) or a resource's client option.

Read with a resource

@Component({
  template: `
    @if (albums.hasValue()) {
      @for (album of albums.value(); track album.id) {
        <li>{{ album.title }} by {{ album.artist?.name }}</li>
      }
    }
    @if (albums.jsonApiError(); as error) {
      <p>{{ error.status }}</p>
    }
  `,
})
export class AlbumList {
  readonly search = signal('')

  readonly albums = jsonApiResource({
    params: () => ({ filter: { title: this.search() } }),
    loader: ({ client, params, abortSignal }) =>
      client.albums.list({ ...params, include: ['artist'], signal: abortSignal }),
  })
}

Changing search starts a new read and cancels the one in flight. Return undefined from params to hold the read until its inputs are ready. As with any Angular resource, value() throws in the error state, so guard it with hasValue().

nextPage(list) and prevPage(list) return the page params from a collection's links, ready to set on the signal your params read. loadAll(firstPage, { signal }) follows next links and returns every member in one array.

Write with a mutation

readonly rename = jsonApiMutation((client, title: string) =>
  client.albums.id(this.id()).update({ title }),
)

save(title: string) {
  this.rename.mutate(title).then(() => this.albums.reload(), () => {})
}

isPending(), error(), jsonApiError(), value() and reset() track the latest call. Nothing is cached between resources, so reload the reads a write affects.

TanStack Query

For a shared cache, the @haddowg/json-api-angular/query entry point runs the client on TanStack Query with the type:id normalised cache from @haddowg/json-api-query: a write updates every cached read of the resources it returns, with no refetch. It needs Angular 20.1 or later (TanStack's own floor; the root entry above still works on 20.0) and two more packages, which are optional peer dependencies of this one. @tanstack/angular-query is ES modules only, so a CommonJS require of the entry needs Node.js 20.19 or later, the floor this package declares:

npm install @tanstack/angular-query @haddowg/json-api-query

Build the QueryClient with a JsonApiMutationCache, which runs every write's cache upkeep, and install the generated resourceMap with provideJsonApiQuery:

import { JsonApiMutationCache } from '@haddowg/json-api-query'
import { provideJsonApiQuery } from '@haddowg/json-api-angular/query'
import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query'
import { createClient, resourceMap } from './api/music.gen'

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(withInterceptors([authInterceptor])),
    provideJsonApiClient(createClient, { baseUrl: '/api/v5' }),
    provideTanStackQuery(() => new QueryClient({ mutationCache: new JsonApiMutationCache() })),
    provideJsonApiQuery(resourceMap),
  ],
}

Then pass the client's bound factories to TanStack's own injectQuery, injectInfiniteQuery and injectMutation. They are typed by the Register above, and the jsonApiError pipe narrows an error() to its JsonApiError:

import {
  injectJsonApiReads,
  injectJsonApiWrites,
  JsonApiErrorPipe,
} from '@haddowg/json-api-angular/query'
import { injectMutation, injectQuery } from '@tanstack/angular-query'

@Component({
  imports: [JsonApiErrorPipe],
  template: `
    <h1>{{ album.data()?.title }}</h1>
    @if (rename.error() | jsonApiError; as error) {
      <p>{{ error.byPath()['title']?.[0]?.detail }}</p>
    }
  `,
})
export class AlbumPage {
  private readonly reads = injectJsonApiReads()
  private readonly writes = injectJsonApiWrites()
  readonly id = input.required<string>()

  readonly album = injectQuery(() => this.reads.albums.get(this.id(), { include: ['artist'] }))
  readonly rename = injectMutation(() => ({
    ...this.writes.albums.id(this.id()).update({ optimistic: true }),
    onSuccess: () => this.toast.show('Saved'), // the cache upkeep runs regardless
  }))
}

A second server shares the QueryClient in a scope of its own: provideJsonApiQuery(adminMap, { client: ADMIN_API, scope: 'admin' }), then injectJsonApiReads(ADMIN_API). provideJsonApiQuery fails at startup if provideTanStackQuery is missing or its QueryClient has no JsonApiMutationCache.

See the Angular guide for the details.

License

MIT