1.0.2 • Published 5 years ago

@hafdon/sierra-api v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

sierraApi

Wrapper around Innovative (III) Sierra API

installation

npm i @hafdon/sierra-api

configuration file

/// sierra-api.config.local.js
module.exports = {
    access: 'write' | 'read',
    key: '<key provided by iii>',
    secret: '<your secret>',
    urlBase: '/iii/sierra-api',
    version: 'v5',
    port: 443,
    host: '<your local host>',
};

methods

api._ ({
    path: // uri
    method: // 'GET' | 'POST' | 'PATCH' | 'DELETE'
    body: //
    qs: //
})

use with express.app()

require('dotenv').config()
const express = require('express')
const config =  require('./sierra-api.config.local')

// import (async) sierraApi module
const SierraApi = require('@hafdon/sierra-api')

// create class instance of the sierraApi module
const sierraApi = new SierraApi(config);

const app = express()
const port = process.env.PORT | <default port>

app.all('/*', (async (req, res, next) => {

    try {
        const { body, statusCode } = await sierraApi._({
            "path": req.path,
            "method": req.method,
            "body": req.body,
            "qs": req.query
        })

        // if body.entries doesn't exist, it means the body has our data object (because we're not getting back a list of things)
        const data = (body ? (body.entries ? body.entries : body) : {})
        res.status(statusCode).send(data)
    } catch (e) {
        console.log(e)
        // error-handling logic here
        res.status(404).send({"message": "Error"})
    }
}))

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

debug statements

  • appear on sierra-api

testing

  • no testing yet
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago