Bootstruct
Bootstruct is a web framework for Node, based on a folder-structure / file-name convention.
Routing by structure.
Table of contents
- Overview (this page)
- Get Started
- Docs
Overview
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
ย
Controling Request Flow
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?
ย
Naming Convention
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
ย
What Else?
- Create your own hook
- Handle dynamic url params (e.g.
/A/B/whatever
) - Extend Bootstruct's different prototypes and more.
ย
Bootstruct:
- saves you from coding your routes.
- enforces a natural code separation by concept.
- provides you with great control over request flow.
- is extensible.
ย
Start Using Bootstruct
Questions, suggestions, criticism, bugs, hugs, typos and kudos are all welcome.
taitu.dev (at) gmail dot com