@agnostack/aftership-request
Version:
Please contact agnoStack via info@agnostack.com for any questions
83 lines (63 loc) • 1.82 kB
Markdown
# @agnostack/aftership-request
> 🎮 Minimal [AfterShip](https://docs.aftership.com/api/4/overview) API request library for Node
## Installation
```bash
yarn add @agnostack/aftership-request # npm install @agnostack/aftership-request
```
## Quickstart (OAuth)
```js
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
```js
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.
```js
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](https://www.linkedin.com/in/adamgrohs/) @ [agnoStack](https://agnostack.com/) for any questions._