🚀 DAY 4 OF LAUNCH WEEK: Introducing GitHub Actions Scanning Support.Learn more →
Socket
Book a DemoInstallSign in
Socket

chec-request

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chec-request

🔌 Lightweight Chec client for Node, browsers and simple apps or serverless functions

Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

chec-request

🔌 Lightweight Chec client for Node, browsers and simple apps or serverless functions

Quickstart

Send requests with a function, or with a Chec instance.

const { Chec, request } = require('chec-request');

const commerce = new Chec('CHEC_API_TOKEN');

commerce.get('products').then(products => console.log(products));

// Or with a simple request

request(endpoint, { token: 'CHEC_API_TOKEN' }).then(data => console.log(data));

Examples

Some API endpoints require a secret key, you should check the API documentation and pass the applicable TOKEN.

GET

const { Chec, request } = require('chec-request');

const commerce = new Chec('CHEC_API_TOKEN');

commerce
  .get('products/prod_f89398fs489g')
  .then(products => console.log(products));

// Or with a simple request

request('products', {
  token: 'CHEC_API_TOKEN',
}).then(products => console.log(products));

POST

const { Chec, request } = require('chec-request');

const data = {
  code: 'RHKZKU71WG',
  type: 'fixed',
  value: '49.95',
  limit_quantity: 1,
  quantity: 10,
  expires: 0,
};

const commerce = new Chec('CHEC_API_TOKEN');

commerce.post('discounts', data).then(discount => console.log(discount));

// Or with a simple request

request('discounts', {
  token: 'CHEC_API_TOKEN',
  method: 'POST',
  data,
}).then(data => console.log(data));

PUT

const { Chec, request } = require('chec-request');

const data = {
  customer: {
    firstname: 'Jamie',
    lastname: 'Barton',
  },
};

const commerce = new Chec('CHEC_API_TOKEN');

commerce.put('orders/orderId', data).then(discount => console.log(discount));

// Or with a simple request

request('orders/orderId', {
  token: 'CHEC_API_TOKEN',
  method: 'PUT',
  data,
}).then(data => console.log(data));

DELETE

const { Chec, request } = require('chec-request');

const commerce = new Chec('CHEC_API_TOKEN');

commerce.delete('discounts/RHKZKU71WG').then(res => console.log(res));

// Or with a simple request

request('discounts/RHKZKU71WG', {
  token: 'CHEC_API_TOKEN',
  method: 'DELETE',
}).then(res => console.log(res));

FAQs

Package last updated on 29 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts