TypeScript icon, indicating that this package has built-in type declarations

2.5.1 • Public • Published


DatX is an opinionated data store for use with the MobX state management library. It features support for simple observable property definition, references to other models and first-class TypeScript support.

@datx/jsonapi is a datx mixin that adds JSON API support.

Basic usage

import { Collection, Model, Attribute } from '@datx/core';
import { jsonapiCollection, jsonapiModel } from '@datx/jsonapi';
import { computed } from 'mobx';

class Person extends jsonapiModel(Model) {
  public static type = 'person'; // Unique name of the model class

  public name: string; // A normal observable property without a default value

  public surname: string;

  @Attribute({ toOne: Person })
  public spouse?: Person; // A reference to a Person model

  public get fullName() {
    // Standard MobX computed props
    return `${this.name} ${this.surname}`;

class AppData extends jsonapiCollection(Collection) {
  public static types = [Person]; // A list of models available in the collection

const store = new AppData();
const john = store.add(new Person({ name: 'John', surname: 'Smith' })); // Add a model instance to the store
const jane = store.add({ name: 'Jane', surname: 'Smith', spouse: john }, Person); // Add a model to the store

await john.save(); // POST to the server
const people = await store.fetchAll(Person); // Get all people from the server

Getting started

Note: @datx/jsonapi has a peer dependency to mobx@^4.2.0 or mobx@^5.5.0, so don't forget to install the latest MobX version:

npm install --save @datx/jsonapi mobx


The lib makes use of the following features that are not yet available everywhere. Based on your browser support, you might want to polyfill them:

How to add the polyfills. Note: Fetch API is not included in the polyfills mentioned in the Troubleshooting page. Instead, you need to add it as a separate library. If you don't have any special requirements (like server-side rendering), you can use the window.fetch polyfill.

API reference


Having issues with the library? Check out the troubleshooting page or open an issue.

Build Status npm version Dependency Status devDependency Status


The MIT License


datx-jsonapi is maintained and sponsored by Infinum.


npm i @datx/jsonapi

DownloadsWeekly Downloads






Unpacked Size

339 kB

Total Files


Last publish


  • danipavic
  • kristian240
  • infinumcom
  • darkokukovec
  • safo6m
  • fvoska
  • ivicabatinic