fs-to-http-builder

1.0.0 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i fs-to-http-builder

Weekly Downloads

6

Version

1.0.0

License

MIT

Unpacked Size

10.8 kB

Total Files

4

Last publish

Collaborators

  • mdhornet90