fs-to-http-builder
A utility that can generate express route information from your project's filesystem
Last updated 7 months ago by mdhornet90 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fs-to-http-builder 
SYNC missed versions from official npm registry.

CircleCI npm version Mutation testing badge

fs-to-http-builder

A utility that can generate Express routes from your project's filesystem

Overview

This tool attempts to free you up from having to manually declare routes while still providing you the flexibility to structure your project how you please.

By default, the tool will crawl through your project's filesystem and search for non-test files inside of any folder named "endpoints" (treating "endpoints" as the root path), and create route information for any files or functions inside of files named any of the following:

  • post
  • get
  • put
  • patch
  • delete

This information can then be fed into Express directly.

Custom matchers

In addition to the built-in route matchers that come bundled by default with the tool, you can add custom matchers to handle more complex cases. If you feel the matcher you create is useful, please open a PR to petition for its inclusion as a default!

An Example

If you have a folder structure like the following:

{
    src: {
        a: {
            endpoints: {
                foo.js (contains function 'get')
            }
        },
        b: {
            endpoints: {
                bar: {
                    post.js
                },
                baz: {
                    _id: {
                        put.js
                        delete.js
                    }
                }
            }
        }
    }
}

The tool will generate the following route information:

[
    {
        route: '/foo',
        method: 'get',
        handler: 'get()'
    },
    {
        route: '/bar',
        method: 'post',
        handler: 'default()' // from post.js
    },
    {
        route: '/baz/:id',
        method: 'put',
        handler: 'default()' // from put.js
    },
    {
        route: '/baz/:id',
        method: 'delete',
        handler: 'default()' // from delete.js
    }
]

Love it? Hate it? I want to know!

This project was inspired by code in a work project and extended to work with a side project of mine so I fully expect that I made assumptions other people would not - I'll attempt to add some of the first issues myself to track what are likely going to be points of pain for new users, but if the tool isn't working as you'd expect feel free to open up an issue on the project's Issues page.

Current Tags

  • 0.1.0                                ...           latest (7 months ago)

5 Versions

  • 0.1.0                                ...           7 months ago
  • 0.0.4                                ...           9 months ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |