Naturally Pacifist Marsupials
Miss any of our Open RFC calls?Watch the recordings here! »

@agnostack/aftership-request

1.0.3 • Public • Published

@agnostack/aftership-request

🎮 Minimal AfterShip API request library for Node

Installation

yarn add @agnostack/aftership-request # npm install @agnostack/aftership-request 

Quickstart (OAuth)

const { createClient } = require('@agnostack/aftership-request');
// import { createClient } from '@agnostack/aftership-request'
 
const aftership = new createClient({
  api_key: '...' // AfterShip API key.
});
 
aftership
  .get('couriers')
  .then(console.log)
  .catch(console.error);
 
aftership
  .post('trackings', {
    tracking: {
      tracking_number: 'RA123456789HK',
      slug: 'usps'
    }
  })
  .then(console.log)
  .catch(console.error);
 
aftership
  .put('trackings/:slug/:tracking_number', {
    tracking: {
      title: 'New Title'
    }
  })
  .then(console.log)
  .catch(console.error);

Kitchen sink

const aftership = new createClient({
  api_key: '...',
  api_domain: '...',
  version: 'v4',
  headers: {
    // ...
  }
});

Custom headers per request

The API provides you the ability to send various request headers that change the way data is stored or retrieved.

By default this library will encode all data as JSON, however you can customise this by setting your own Content-Type header as an additional argument to get, post, put and delete.

Note: If you add the Content-Type custom header to post, put or delete you will need to encode data yourself.

const aftership = new createClient({
  api_key: '...'
});
 
const headers = {
  'X-My-Header': 'custom'
};
 
aftership
  .get('couriers', headers)
  .then(console.log)
  .catch(console.error);

Contact Adam Grohs @ agnoStack for any questions.

Install

npm i @agnostack/aftership-request

DownloadsWeekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

21.8 kB

Total Files

18

Last publish

Collaborators

  • avatar