andrecedik / shipcloud-js

ShipCloud Bindings for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ShipCloud API Binding for JavaScript

This project provides a complete mapping of ShipCloud's API. At advarics we're currently evaluating their services and because our applications rely heavily on web technologies we've decided to create a proper JS API-binding. As far as we know there aren't any similar projects available.

This projects is still in development. At this time we're only utilizing the Address-Calls of the API. But soon it'll cover the missing parts of the API too.

Structure

We use these fine open source packages and languages:

Api Access Keys

However, to be able to communicate with the API you'll have to register first to obtain the free developer access keys. Then open src/config.json and put your keys in there.

Api Structure

The structure under src/api/v1 strictly follows the original documentation. It comprises of three sub-directories named calls, types and config

Calls directory

This directory contains all available API calls:

For example, the Address-Call comprises of three calls according to the docs: create, index and read

Therefore we define these call-mappings in our Address class: read, readAll and create. In general these classes define the high-level portion of the complete API-binding as these don't touch more specific aspects like JSON or HTTP-Requests.

Types directory

This directory contains all message and response definitions.

Additional Services
Address 
Package 
Pickup 
Rate 
Responses ---
             |
             | ---> Address-Response, 
             | ---> Carrier-Response
             | ---> Pickup-Response 
             | ----> etc.
Shipment 
Shipment Quote 
Tracker 
Webhook

These classes are DTOs for easy transfer between client and server.

Config directory

This directory contains elements which aren't described in the original docs.

Api Auth

Api-Auth class contains some helper methods for auth-key management.

REST & JSON

All API calls go via the RequestHelper class. This class utilizes node-fetch and implements the GET, POST, PUT and DELETE requests.

Building

First, install node packages with npm install.

Development bundle

To create a development bundle type:

npm run build:dev 

Production bundle

To create a production bundle type:

npm run build:prod 

After a successful build a new bundle will be created in dist.

Hot-Module reloading with WebPack

To activate hot-module reloading during the development type:

npm run start:hmr 

Usage

This binding can be used in any JavaScript environment as it contains a complete WebPack build setup that generates a bundle in the dist directory. But it also can be used directly in Node by calling npm run start:client. In this case a special node instance called ts-node will load index.ts from the project root and instantiate a small client script. This script initializes the API binding located in src and some of their API calls to query data from ShipCloud.

Here's an example output:

Notice: It depends on your current setup what and if any data will be sent back from ShipCloud. Also, don't forget to check your API key in src/config.json if you experience any problems.

License

MIT

About

ShipCloud Bindings for JavaScript

License:MIT License


Languages

Language:JavaScript 92.1%Language:TypeScript 7.9%