1.2.0 • Published 1 year ago

@randajan/just-api v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@randajan/just-api

NPM JavaScript Style Guide

Goal is to create simple extendable web interface using middlewares

Install

npm install @randajan/just-api

or

yarn add @randajan/just-api

Main methods

import createInterface, {
    logger,
    showError,
    showTime,
    addContext,
    formatInput,
    toJSON
} from "@randajan/just-api/sync";




const api = createInterface([
    toJSON(),
    logger(true),
    showTime(),
    showError(),
    addContext({any:"thing"}),
    formatInput(({query})=>query),
    ({request:{input}, context})=>{
        return input.foo + " | " + context.any;
    }
]);


console.log(api({query:{foo:"bar"}}));
//expected output - {"output":"bar | thing","time":{"start":"2023-01-03T02:02:00.723Z","end":"2023-01-03T02:02:00.723Z","duration":0}}

License

MIT © randajan