Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.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

latest
Source
npmnpm
Version
1.2.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)
);

Install

npm install chec-request

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));

GET with params

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

const commerce = new Chec('CHEC_API_TOKEN');

commerce
  .get('products', {
    limit: 5,
    category_slug: 'accessories',
  })
  .then((products) => console.log(products))
  .catch((err) => console.log(err));

// Or with a simple request

request('products', {
  token: 'CHEC_API_TOKEN',
  params: {
    limit: 5,
    category_slug: 'accessories',
  },
})
  .then((products) => console.log(products))
  .catch((err) => console.log(err));

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));

Initialize with options

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

const commerce = new Chec('CHEC_API_TOKEN', {
  baseUrl: 'http://localhost:5000',
  version: 'v2',
});

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

// Or with a simple request

request('products', {
  token: 'CHEC_API_TOKEN',
  options: {
    baseUrl: 'http://localhost:5000',
    version: 'v2',
  },
}).then((res) => console.log(res));

Initialize with headers

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

const commerce = new Chec('CHEC_API_TOKEN', {
  headers: {
    'Custom-Header': 'some value',
  },
});

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

// Or with a simple request

request('merchant', {
  token: 'CHEC_API_TOKEN',
  options: {
    headers: {
      'Custom-Header': 'some value',
    },
  },
}).then((res) => console.log(res));

Keywords

ecommerce

FAQs

Package last updated on 21 Mar 2021

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