Constructor
new Fetcher(url, headersopt)
Construcotr
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url | string | Base url | |
headers | Headers | <optional> | Header data. |
- Source
Examples
const fetcher = new Fetcher( 'https://api.example.com' );
fetcher.get( '/books', function( err, result ) { } );
const fetcher = new Fetcher( 'https://api.example.com' );
try
{
const result = await fetcher.get( '/books' );
}
catch( e )
{
// Handle error
}
Methods
(async) delete(endpoint, cbopt) → {Promise.<(any|undefined)>}
DELETE call
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
endpoint | string | API endpoint | ||
cb | function | <optional> | null | Callback function |
- Source
Returns:
- Type:
- Promise.<(any|undefined)>
(async) get(endpoint, cbopt) → {Promise.<(any|undefined)>}
GET call
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
endpoint | string | API endpoint | ||
cb | function | <optional> | null | Callback function |
- Source
Returns:
- Type:
- Promise.<(any|undefined)>
(async) patch(endpoint, dataopt, cbopt) → {Promise.<(any|undefined)>}
PATCH call
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
endpoint | string | API endpoint | ||
data | object | <optional> | {} | Patch data |
cb | function | <optional> | null | Callback function |
- Source
Returns:
- Type:
- Promise.<(any|undefined)>
(async) post(endpoint, dataopt, cbopt) → {Promise.<(any|undefined)>}
POST call
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
endpoint | string | API endpoint | ||
data | object | <optional> | {} | Post data |
cb | function | <optional> | null | Callback function |
- Source
Returns:
- Type:
- Promise.<(any|undefined)>
(async) put(endpoint, dataopt, cbopt) → {Promise.<(any|undefined)>}
PUT call
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
endpoint | string | API endpoint | ||
data | object | <optional> | {} | PUT data |
cb | function | <optional> | null | Callback function |
- Source
Returns:
- Type:
- Promise.<(any|undefined)>