Skip to content

DSL implementation for routes declaration. Data-driven and hierarchical.

License

Notifications You must be signed in to change notification settings

lexfrl/routr-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DESCRIPTION

Pure DSL implementation for routes declaration. Data-driven and hierarchical. Pull requests are welcome. See https://github.com/AlexeyFrolov/routr-map/blob/master/src/__tests__/match-url.js for examples. It could be used with React (you can store the "route" in the state tree) and with express to parse url. The only responsibility is to match and url (buildUrl from route match result).

The idea is to declare routes as a tree where for each node you can attach additional meta-info like so:

{
    "users": {
        _defaults: { // Optional. Routes are just data you can attach any meta, such as default values
          handler: (req, res) => {},
        }
        ":id": {
            "comments": {
              _defaults: {
                 handler: (req, res) => {},
                 security: (req,res) => {}
              }
            },
            "likes": {}}
    },
    "posts": {

    }
}

Example

https://gist.github.com/AlexeyFrolov/eebb41610f0d97d282ce

Inspired by https://gist.github.com/AlexeyFrolov/f14ab900df8e10fab831

TODO

  • support for defaults
  • docs

About

DSL implementation for routes declaration. Data-driven and hierarchical.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published