Scalability: NanoAPI allows you to scale your codebase by breaking it down into smaller, more manageable pieces
Performance: By breaking down your codebase into smaller pieces, you can optimize performance by only loading the code you need
Maintainability: NanoAPI makes it easier to maintain your codebase by allowing your team to work on a monolith (developer-friendly) while deploying microservices (production-friendly)
Robustness: NanoAPI makes your codebase more robust by allowing you to split out that annoying, flaky API endpoint into its own service
Underneath the hood, NanoAPI uses annotations to define subgroups of your API. These subgroups can be as granular as a single endpoint or as broad as a collection of endpoints.
NanoAPI then transpiles your codebase based on these subgroups into microservices or per-endpoint nanoservices.
At build-time, NanoAPI ingests your codebase and converts the code into an Annotated Language Tree (ALT). This tree is then used to display the overview in the UI or generate the microservices or nanoservices.
Let's say you have the following Node.js Express codebase as an example:
// index.js
import express from 'express';
const app = express();
const port = 3000;
app.get('/random', (req, res) => {
res.send(Math.random());
});
app.post('/wordCount', (req, res) => {
const { text } = req.body;
res.send(text.split(' ').length);
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
NanoAPI can split this codebase into two separate services: one for the /random
endpoint and one for the /wordCount
endpoint. After running a split build, you would have the following two files in an output folder:
// /dist/0/index.js
import express from 'express';
const app = express();
const port = 3000;
app.get('/random', (req, res) => {
res.send(Math.random());
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
// dist/1/index.js
import express from 'express';
const app = express();
const port = 3000;
app.post('/wordCount', (req, res) => {
const { text } = req.body;
res.send(text.split(' ').length);
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
By default, NanoAPI will split your endpoints into one endpoint per file. However, you can customize this behavior by defining your own subgroups in the UI or through annotations. You can read more on this topic in Understanding Annotations.
You can check out the Getting Started guide to learn how to set up NanoAPI in your project.
Or if you just want to poke around for yourself, you can install NanoAPI via npm or yarn. View on Github
npm install -g @nanoapi.io/napi
yarn global add @nanoapi.io/napi
Note: NanoAPI is growing its list of languages it supports. Check out our Language Support Roadmap to see what's coming next.