Skip to content
JSON API client library for Angular 5+ πŸ‘Œ :: Production Ready πŸš€
TypeScript JavaScript
Branch: v2.1
Clone or download
maxi7587 and pablorsk Use is new instead of id on save (#260)
* added test to service and fix test factory
* prettier
* detail
* fix-resource-has-one-relationships
* added include_get and include_save params to IParamsResource
* replaced ID for is_new and added tests
Latest commit 6b4ff69 Jan 17, 2020
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Support transpiling to ES6 (#245) Oct 24, 2019
demo Support transpiling to ES6 (#245) Oct 24, 2019
docs fix/vulnerabilities packages upgraded (#216) Sep 12, 2019
scripts tslint on CI (#80) Jun 11, 2018
src Use is new instead of id on save (#260) Jan 17, 2020
.editorconfig Feature/new yarn schema (#11) Dec 18, 2017
.gitattributes demo updated (#212) Sep 9, 2019
.gitignore CI: First steps (#79) Jun 10, 2018
.htmlhintrc inital files for library on angular4 Oct 8, 2017 Use is new instead of id on save (#260) Jan 17, 2020 CI: First steps (#79) Jun 10, 2018
LICENSE Feature: Json Ripper and Data Providers (#221) Oct 4, 2019
angular.json v2 RC.1 (#108) Sep 5, 2018
jest.base.config.js Feature: Json Ripper and Data Providers (#221) Oct 4, 2019
jest.demo.config.js jest updgrade (#220) Sep 14, 2019
jest.lib.config.js jest updgrade (#220) Sep 14, 2019
package.json Save only dirty (#251) Dec 23, 2019
protractor.conf.js Feature/new yarn schema (#11) Dec 18, 2017
setup-jest.ts Karma removed (#82) Jun 27, 2018
tslint.json fixes lint Nov 1, 2018
yarn.lock Save only dirty (#251) Dec 23, 2019


angular jsonapi

CircleCI Codacy Badge npm version Coverage Status

This is a JSON API library for Angular 6+. Please use [ts-angular-jsonapi]( for AngularJS.

Online demo

You can test library on this online example πŸ‘Œ

demo app

Data is obtained from Json Api Playground server.

Supported features

  • Cache (on memory): TTL for collections and resources. Before a HTTP request objects are setted with cached data.
  • Cache on IndexedDB
  • Pagination
  • Sorting
  • Include param support (also, when you save)
  • Equal requests, return a same ResourceObject on memory
  • Default values for a new resource (hydrator).



Just install, configure and learn with examples.

First of all, it's advisable to read Jsonapi specification. Understanding JsonApi documents structure is recommended.


yarn add ngx-jsonapi@2.0.0-rc.4 --save
# or npm if you wish...

Dependecies and customization

  1. Add Jsonapi dependency.
  2. Configure your url and other paramemeters.
  3. Inject JsonapiCore somewhere before you extend any class from Jsonapi.Resource.
import { NgModule } from '@angular/core';
import { NgxJsonapiModule } from 'ngx-jsonapi';

    imports: [
            url: '//'
export class AppModule {}


Like you know, the better way is with examples. Lets go! πŸš€

Defining a resource


import { Injectable } from '@angular/core';
import { Autoregister, Service, Resource, DocumentCollection, DocumentResource } from 'ngx-jsonapi';
import { Book } from '../books/books.service';
import { Photo } from '../photos/photos.service';

export class Author extends Resource {
    public attributes = {
        name: 'default name',
        date_of_birth: ''

    public relationships = {
        books: new DocumentCollection<Book>(),
        photo: new DocumentResource<Photo>()

export class AuthorsService extends Service<Author> {
    public resource = Author;
    public type = 'authors';

Get a collection of resources


import { Component } from '@angular/core';
import { DocumentCollection } from 'ngx-jsonapi';
import { AuthorsService, Author } from './../authors.service';

    selector: 'demo-authors',
    templateUrl: './authors.component.html'
export class AuthorsComponent {
    public authors: DocumentCollection<Author>;

    public constructor(private authorsService: AuthorsService) {
                // include: ['books', 'photos'],
            .subscribe(authors => (this.authors = authors));

View for this controller

<p *ngFor="let author of; trackBy: authors.trackBy">
    id: {{ }} <br />
    name: {{ }} <br />
    birth date: {{ author.attributes.date_of_birth | date }}

Collection sort

Example: name is a authors attribute, and makes a query like /authors?sort=name,job_title

let authors = authorsService.all({
    sort: ['name', 'job_title']

Collection filtering

Filter resources with attribute: value values. Filters are used as 'exact match' (only resources with attribute value same as value are returned). value can also be an array, then only objects with same attribute value as one of values array elements are returned.

    remotefilter: { country: 'Argentina' }

Get a single resource

From this point, you only see important code for this library. For a full example, clone and see demo directory.


More options? Include resources when you fetch data (or save!)

authorsService.get('some_author_id', { include: ['books', 'photos'] });

TIP: these parameters work with all() and save() methods too.

Add a new resource

let author =; = 'Pablo Reyes';
author.attributes.date_of_birth = '2030-12-10';;

Need you more control and options?

let author =; = 'Pablo Reyes';
author.attributes.date_of_birth = '2030-12-10';

// some_book is an another resource like author
let some_book = booksService.get(1);

// some_publisher is a polymorphic resource named company on this case
let some_publisher = publishersService.get(1);
author.addRelationship(some_publisher, 'company');

// wow, now we need detach a relationship
author.removeRelationship('books', 'book_id');

// this library can send include information to server, for atomicity{ include: ['book'] });

// mmmm, if I need get related resources? For example, books related with author 1
let relatedbooks = booksService.all({ beforepath: 'authors/1' });

// you need get a cached object? you can force ttl on get
let author$ = authorsService.get(
    { ttl: 60 } // ttl on seconds (default: 0)

Update a resource

authorsService.get('some_author_id').suscribe(author => { += 'New Name'; => {
        console.log('author saved!');


  // get page 2 of authors collection, with a limit per page of 50
  page: { number: 2 ;  size: 50 }

Collection page

  • number: number of the current page
  • size: size of resources per page (it's sended to server by url)
  • information returned from server (check if is avaible) total_resources: total of avaible resources on server resources_per_page: total of resources returned per page requested

Local Demo App

You can run JsonApi Demo App locally following the next steps:

git clone
cd ngx-jsonapi
yarn start

We use as backend Json Api Playground.


Check Environment development file πŸ˜‰.

You can’t perform that action at this time.