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.30.0/dist/monster.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.30.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.30.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'));

Classes

WriteError

the error is thrown by the rest api in case of error

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

mapping Object

the mapping is applied before writing.

Properties
Name Type Description
transformer String

Transformer to select the appropriate entries

report Object
Properties
Name Type Description
path String

Path to validations

mapping.callback Array.<Monster.Data.Datasource~exampleCallback>

with the help of the callback, the structures can be adjusted before writing.

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

read.mapping Object

the mapping is applied after reading.

Properties
Name Type Description
transformer String

Transformer to select the appropriate entries

callback Array.<Monster.Data.Datasource~exampleCallback>

with the help of the callback, the structures can be adjusted after reading.

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
WriteError
Returns:
Type
Promise