@pollen-solutions/api-request
v0.0.3
Published
Pollen Solutions - JS - Api Request
Downloads
50
Maintainers
Readme
API Request
Installation
npm i @pollen-solutions/api-request
Usage
This documentation uses the API JSON placeholder.
Basic Usage
import {ApiRequest} from "@pollen-solutions/api-request"
ApiRequest(
'https://jsonplaceholder.typicode.com/posts', /** Endpoint url */
{_start:0, _limit:5}, /** Data request arguments */
'GET', /** HTTP Request Method */
{'X-CUSTOM-HEADER': 'My Custom Header'}, /** HTTP Headers */
function(json) {
console.log(json)
}, /** Callback function for processing the response in JS format */
true /** Debug mode enabled */
)
Using promise return
import {ApiRequest} from "@pollen-solutions/api-request"
ApiRequest('https://jsonplaceholder.typicode.com/posts', {
_start: 0,
_limit: 5
})
.then(json => console.log(json))
.finally(() => console.log('ApiRequest complete'))
For a specific HTTP verb
GET Request
import {ApiGet} from "@pollen-solutions/api-request"
ApiGet('https://jsonplaceholder.typicode.com/posts').then(json => console.log(json))
POST Request
import {ApiPost} from "@pollen-solutions/api-request"
ApiPost('https://jsonplaceholder.typicode.com/posts', {
title: 'foo',
body: 'bar',
userId: 1,
}).then(json => console.log(json))
PUT Request
import {ApiPut} from "@pollen-solutions/api-request"
ApiPut('https://jsonplaceholder.typicode.com/posts/1', {
id: 1,
title: 'foo',
body: 'bar',
userId: 1,
}).then(json => console.log(json))
PATCH Request
import {ApiPatch} from "@pollen-solutions/api-request"
ApiPatch('https://jsonplaceholder.typicode.com/posts/1', {
title: 'foo',
}).then(json => console.log(json))
DELETE Request
import {ApiDelete} from "@pollen-solutions/api-request"
ApiDelete('https://jsonplaceholder.typicode.com/posts/1')