New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

bootstruct

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bootstruct

Routing by structure. A name-convention web framework for Node.js.


Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created

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

FAQs

Package last updated on 17 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts