Bootstruct is a web framework for Node, based on a folder-structure / file-name convention.
Routing by structure.
- Overview (this page)
- Get Started
- Docs
Creating web apps with Node requires wiring up our routes, we need to bind different URL paths to their handlers. We usually do that by declerative coding. Something like: bind('GET', '/api/books', handler)
.
With Bootstruct you don't code your routes. You just export your handler and name the file with its route name.
Technically, Bootstruct creates routes by parsing your routes folder and routes requests through that folder's structure, matching URLs to corresponding paths under that folder.
Meaning, to support routes like:
domain.com/
domain.com/A
domain.com/A/B
domain.com/A/B/C
your routes folder tree would generally look like:
├── routes
│ ├── index.js
│ └── A
│ ├── index.js
│ └── B
│ ├── index.js
│ └── C
│ └──index.js
When working with middlware functions (express
, connect
...) you control request flow by binding 'this' route before 'that' route. The order in which you code your routes matters.
Bootstruct provides you with an onion-like layered app by leveraging the parental folder chain. So a request to /A/B/C
would go through:
1. /
2. /A
3. /A/B
4. /A/B/C
5. /A/B
6. /A
7. /
Do you see the onion?
Bootstruct uses files and folders with certain names as different hooks.
For example, to handle GET
requests, name your handler file _get.js
. To handle POST
requests, name it _post.js
.
You can create your own hooks
- Create your own hook
- Handle dynamic url params (e.g.
/A/B/whatever
) - Extend Bootstruct's different prototypes and more.
- saves you from coding your routes.
- enforces a natural code separation by concept.
- provides you with great control over request flow.
- is extensible.
Questions, suggestions, criticism, bugs, hugs, typos and kudos are all welcome.
taitu.dev (at) gmail dot com