RestAPI

Monster.Data.Datasource. RestAPI

You can create an object of this class using the monster namespace Monster.Data.Datasource.RestAPI().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.23.0/dist/modules/data/datasource/restapi.js';
Monster.Data.Datasource.RestAPI()
</script>

Alternatively you can import the class directly

<script type="module">
import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.23.0/dist/modules/data/datasource/restapi.js';
new RestAPI()
</script>

Constructor

# new RestAPI(readDefinitionopt, writeDefinitionopt)

The LocalStorage class encapsulates the access to data objects.

Parameters:
Name Type Attributes Description
readDefinition Object <optional>

An options object containing any custom settings that you want to apply to the read request.

writeDefinition Object <optional>

An options object containing any custom settings that you want to apply to the write request.

Since:
  • 1.22.0
Throws:

value is not a string

Type
TypeError
Example
import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.23.0/dist/modules/data/datasource/restapi.js';

const ds = new RestAPI({
  url: 'https://httpbin.org/get'
},{
  url: 'https://httpbin.org/post'
});

ds.set({flag:true})
ds.write().then(()=>console.log('done'));
ds.read().then(()=>console.log('done'));

Members

# defaults

Properties
Name Type Default Description
url string

Defines the resource that you wish to fetch.

write Object {}

Options

Properties
Name Type Default Description
init Object {}

An options object containing any custom settings that you want to apply to the request. The parameters are identical to those of the Request constructor

Properties
Name Type Default Description
method string POST
acceptedStatus string [200,201
url string

URL

read.init Object {}

An options object containing any custom settings that you want to apply to the request. The parameters are identical to those of the Request constructor

Properties
Name Type Default Description
method string GET
read.acceptedStatus string [200
read.url string

URL

Methods

# getClone() → {RestAPI}

Returns:
Type
RestAPI

# read() → {Promise}

Throws:
  • the options does not contain a valid json definition

    Type
    Error
  • value is not a object

    Type
    TypeError
  • the data cannot be read

    Type
    Error
Returns:
Type
Promise

# write() → {Promise}

Throws:

the data cannot be written

Type
Error
Returns:
Type
Promise