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

0.4.0 • Public • Published

ra-data-lb4

Travis (.org) branch npm npm bundle size GitHub

React Admin Loopback4 CRUD DataProvider

Installation

npm i --save ra-data-lb4

Usage

// in src/App.tsx
import React from "react";
import { Admin, Resource } from "react-admin";
import lb4Provider from "ra-data-lb4";

import { PostList } from "./posts";

const App = () => (
    <Admin dataProvider={lb4Provider("http://path.to.my.api/")}>
        <Resource name="posts" list={PostList} />
    </Admin>
);

export default App;

Model Aggregation

Loopback4 supports model aggregations using inclusion resolvers, you can pass your include params per model:

// in src/App.tsx
import { Admin, Resource } from "react-admin";
import lb4Provider from "ra-data-lb4";

const aggregate = (resource: string) => {
    if (resource === "posts") {
        return [
            {
                relation: "author",
            },
        ];
    }

    return [];
};

const provider = lb4Provider("http://path.to.my.api/", aggregate);

Customizing Http Client

// in src/App.tsx
import { fetchUtils, Admin, Resource } from "react-admin";
import lb4Provider from "ra-data-lb4";

const httpClient = (url, options = {}) => {
    if (!options.headers) {
        options.headers = new Headers({ Accept: "application/json" });
    }
    // add your own headers here
    options.headers.set("X-Custom-Header", "foobar");
    return fetchUtils.fetchJson(url, options);
};

const provider = lb4Provider("http://path.to.my.api/", undefined, httpClient);

Contributors

License

This project is licensed under the MIT license.
Copyright (c) KoLiBer (koliberr136a1@gmail.com)

Package Sidebar

Install

npm i ra-data-lb4

Weekly Downloads

15

Version

0.4.0

License

MIT

Unpacked Size

19.8 kB

Total Files

6

Last publish

Collaborators

  • koliber