@randajan/just-api
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