@tg-resources/superagent
TypeScript icon, indicating that this package has built-in type declarations

3.2.1 • Public • Published

tg-resources Superagent backend

NPM version

Installing

Using NPM

npm i tg-resources @tg-resources/superagent

Or using Yarn

yarn add tg-resources @tg-resources/superagent

Does it work on react native?

YES

Basic Usage

import { Router } from "tg-resources"
import { SuperagentResource } from "@tg-resources/superagent"

const onLoad = result => console.log(result);
const onError = result => console.error(result);


const api = new Router({
    cats: new SuperagentResource('/cats'),
    cat: new SuperagentResource('/cats/${pk}')
}, {
    apiRoot: '/api/v1' // Set api root
});

// Do a get request to /api/v1/cats?gender=M
api.cats.fetch(null, {gender: 'M'}).then(onLoad, onError);

// Do a head request to /api/v1/cats?gender=M
api.cats.head(null, {gender: 'M'}).then(onLoad, onError);

// Do a post request to /api/v1/cats with data: {name: 'Twinky', gender: 'M'}
api.cats.post(null, {name: 'Twinky', gender: 'M'}).then(onLoad, onError);

// Do a patch request to /api/v1/cats/1 with data: {name: 'Tinkelberg'}
api.cat.patch({pk: 1}, {name: 'Tinkelberg'}).then(onLoad, onError);

// Do a put request to /api/v1/cats with data: {pk: 1, name: 'Twinky'}
api.cats.put(null, {pk: 1, name: 'Twinky', gender: 'M'}).then(onLoad, onError);

// Do a delete request to /api/v1/cats/1 with data: {'free':'yes'}
api.cat.del({pk: 1}, {free: 'yes'}).then(onLoad, onError);

This package is just Resource implementation using superagent. For additional configuration, see Configuration.

License

MIT © Thorgate

/@tg-resources/superagent/

    Package Sidebar

    Install

    npm i @tg-resources/superagent

    Weekly Downloads

    78

    Version

    3.2.1

    License

    MIT

    Unpacked Size

    59.3 kB

    Total Files

    14

    Last publish

    Collaborators

    • thorgate-main
    • jyrno42
    • metsavaht