• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Routing by structure (a Node.js web framework).

License: MIT Build Status

Bootstruct

Bootstruct is a web framework for Node, based on a folder-structure / file-name convention.

Routing by structure.

Table of contents

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