Skip to content

Latest commit

 

History

History
35 lines (30 loc) · 955 Bytes

File metadata and controls

35 lines (30 loc) · 955 Bytes

Fetch

Using this package with Fetch API requires no additional setup, and it can be used as described in API.

Registering Resources


Make sure an instance of Potion is created and use that to register resources:

import {Potion} from 'potion-client/fetch';
const potion = new Potion({prefix: '/api'});

Now the API endpoints can be registered either using the @potion.registerAs() class decorator:

import {Item} from 'potion-client/fetch';
// An instance of Potion is available either globally or imported from somewhere in your app
@potion.registerAs('/foo', {
    readonly: ['name']
})
class Foo extends Item {
    name: string;
}

Or by using the potion.register() method:

import {Item, readonly} from 'potion-client/fetch';
class Foo extends Item {
    @readonly
    name: string;
}
potion.register('/foo', Foo);