0.0.3 • Published 2 years ago

@pollen-solutions/api-request v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

API Request

Latest Stable Version MIT Licensed

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')
0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago