This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.json
6 lines (6 loc) · 4.2 KB
/
params.json
1
2
3
4
5
6
{
"name": "Ftrouter",
"tagline": "A minimal file tree based api router for node rest api's.",
"body": "<p align=\"center\">\r\n<img width=\"125\" src=\"https://raw.githubusercontent.com/barelyhuman/ftrouter/b01e6ebcda3badeb0eb79a7553b592f699226591/docs/logo.svg\" />\r\n</p>\r\n<h1 align=\"center\">ftrouter</h1>\r\n<p align=\"center\">A minimal file tree based api router for building rest api's with node</p>\r\n\r\n### About\r\n\r\nftrouter started as a clone of the Next.js' Api Routes implmentation and is now on it's path to compete with other frameworks as the simplest way to setup API routes. There's been numerous posts on why using the folder tree makes it atomic and easier to handle the separation between logic. While you cannot bundle code with ftrouter since each file is independent of the other and doesn't need the others for its execution.\r\n\r\nThe Idea and Inspiration for the creation remains to be Vercel's Next.js\r\n\r\n### Perks\r\n\r\n- Custom Port and Directory\r\n- Minimal so can be used with any bundler or process handler.\r\n- [Performance](#Performance) focused\r\n- Pre-compiled state for handling route requests\r\n\r\n### Performance\r\n\r\nScreenshot of `autocannon` to benchmark `/api` from the examples folder\r\n\r\n![Performance Image](https://raw.githubusercontent.com/barelyhuman/ftrouter/8884f7e5961855d10bead23fbdb1d25aae33a692/docs/perf.png)\r\n\r\n### Warning\r\n\r\nThis library is still in active development and is bound to have bugs , kindly make sure you use it only for testing and not for production as of now.\r\n\r\n### Installation\r\n\r\n#### Stable Cli\r\n\r\n```sh\r\n# for global install to avoid installing the devDependencies\r\nnpm i -g barelyhuman/ftrouter --only=prod\r\n# for local install to avoid installing the devDependencies\r\nnpm i barelyhuman/ftrouter --only=prod\r\n\r\n```\r\n\r\n#### Canary Cli\r\n\r\n```sh\r\n# for global install to avoid installing the devDependencies\r\nnpm i -g barelyhuman/ftrouter#canary --only=prod\r\n# for local install to avoid installing the devDependencies\r\nnpm i barelyhuman/ftrouter#canary --only=prod\r\n```\r\n\r\n### Usage\r\n\r\nYou can run `ftrouter` in any folder and the `.js` files will be considered as routes.\r\nThe CLI considers the `api` folder to be the root and will pass down http `req,res` to the exported function.\r\n\r\nThen go ahead and create directories and files under any folder as mentioned or check the `examples` folder for reference.\r\n\r\nExample file tree:\r\n\r\nWe create a folder `example` you might want to call it something like `routes` and point `ftrouter` to it using `-d ./routes` to give you an http Server running for the files inside of the `routes` folder.\r\n\r\n```\r\n-example\r\n - api\r\n - me.js // this compiles to <host>:<port>/api/me\r\n - [id].js; // this compile to <host>:<port>/api/<dynamicParameterId>\r\n```\r\n\r\nExample `me.js` that only handles `GET` requests:\r\n\r\n```\r\nmodule.exports = (req, res) => {\r\n if(req.method === 'GET'){\r\n res.writeHead(200, { 'Content-Type': 'text/plain' });\r\n res.write('Hello World!');\r\n res.end();\r\n return;\r\n }\r\n\r\n res.statusCode = 404;\r\n res.end();\r\n return;\r\n};\r\n\r\n\r\n```\r\n\r\nExample `[id].js` that handles the dynamic path param:\r\n\r\n`GET|POST|DELETE /api/1`\r\n\r\n```\r\nmodule.exports = (req, res) => {\r\n res.write('path param ' + JSON.stringify(req.params)) // {\"id\":1};\r\n res.end();\r\n};\r\n\r\n```\r\n\r\nThen run ftrouter on the root folder of the project, this folder should contain the `api` folder or specify a directory using the `-d` or `--dir` command.\r\n\r\n```sh\r\n# If installed globally\r\nftrouter -d ./example\r\n# If installed locally\r\nnpx ftrouter -d ./example\r\n\r\n```\r\n\r\n### CLI Commands\r\n\r\n- `-d | --dir` to specify the directory to be used for routes, defaults to `api`\r\n- `-p | --port` to specify the port to start the http server on , defaults to `3000`\r\n\r\nExample, the following would use the `example` folder as the base path for the routes and start the server on port `3001`\r\n\r\n```sh\r\n ftrouter -d ./example -p 3001\r\n\r\n```\r\n",
"note": "Don't delete this file! It's used internally to help with page regeneration."
}