Wondering what’s next for npm?Check out our public roadmap! »

    chec-request

    1.2.0 • Public • Published

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

    Install

    npm i chec-request

    DownloadsWeekly Downloads

    10

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    7.08 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar