Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
larvitbase-api
Advanced tools
REST http API base framework based on larvitbase
npm i larvitbase-api
In the file index.js:
const Api = require('larvitbase-api');
let api;
api = new Api({
'baseOptions': {'httpOptions': 8001}, // sent to larvitbase
'routerOptions': {}, // sent to larvitrouter
'reqParserOptions': {}, // sent to larvitReqParser
});
api.start(function (err) {}); // callback
// Exposed stuff
//api.base - larvitbase instance
//api.options - the options sent in when instanciated
//api.apiVersions - resolved versions of the API (subfolders to controllers folder)
//api.stop() // close httpServer
Then just start the file from shell:
node index.js
This will provide the following:
Will print your apps README.md when the browser targets http://localhost:8001/
Will run controllers in your apps "controllers/X.X"-folder (or node_module/xxx/controllers/X.X, see larvitfs for details on the virtual filesystem the routing module uses for this). For example /foo will run the controller controllers/1.2/foo.js, given that 1.2 is the latest version. For details about how to write controllers, see larvitbase.
It is also possible to request a specific version fo the API. Consider:
More detailed examples on controllers in node modules
If any controller exists, in any version in the local app, that controller will have priority over all node modules. If a specific version is requested, that version is all that will be searched for in modules. To find a controller in a module of a specific version this version must be present in the local app, even if the directory is empty.
For example, when folder structure that looks like this:
app |__ controllers |__ node_modules |__ dependency |__ controllers |__ v1.0 |__ bar.js
Requests for /bar and /v1.0/bar will return a 404. However, if we create a v1.0 directory in our apps controllers directory (see below), bar.js will be successfully resolved.
app |__ controllers | |__ v1.0 |__ node_modules |__ dependency |__ controllers |__ v1.0 |__ bar.js
Likewise, if any version of the api exists in the local app, unversioned controllers in modules will not be resolved.
We are using semver where we do the following:
Will write everything stored in res.data as JSON directly to the browser as application/json (except for the README.md, that is sent as text/markdown).
FAQs
API framework based on larvitbase
We found that larvitbase-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.