All Projects → artnez → urltree

artnez / urltree

Licence: MIT license
Named URL data structure with support for URL building.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to urltree

Stplanr
Sustainable transport planning with R
Stars: ✭ 352 (+877.78%)
Mutual labels:  routes, routing
Express Env Example
A sample express environment that is well architected for scale. Read about it here:
Stars: ✭ 130 (+261.11%)
Mutual labels:  routes, routing
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-61.11%)
Mutual labels:  routes, routing
router
Bidirectional Ring router. REST oriented. Rails inspired.
Stars: ✭ 78 (+116.67%)
Mutual labels:  routes, routing
laroute
Generate Laravel route URLs from JavaScript.
Stars: ✭ 33 (-8.33%)
Mutual labels:  routes, routing
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+6438.89%)
Mutual labels:  routes, routing
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+4338.89%)
Mutual labels:  routes, routing
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (+5.56%)
Mutual labels:  routes, routing
ertuo
Ertuo: quick routing for PHP
Stars: ✭ 29 (-19.44%)
Mutual labels:  routes, routing
vue-error-page
[NO LONGER MAINTAINED] Provides a wrapper for router-view that allows you to show error pages without changing the URL.
Stars: ✭ 52 (+44.44%)
Mutual labels:  routes, routing
django-js-routes
Expose and perform reverse lookups of Django URLs in the frontend world.
Stars: ✭ 20 (-44.44%)
Mutual labels:  routes, urls
STCRouter
基于标准URL的iOS路由系统,可实现业务模块组件化,控制器之间零耦合,可实现黑白名单控制,可进行native降级到hybrid。
Stars: ✭ 19 (-47.22%)
Mutual labels:  routes, routing
route-descriptor
Single source of truth for routing
Stars: ✭ 17 (-52.78%)
Mutual labels:  routing
HerePy
A library that provides a Python interface to the HERE APIs.
Stars: ✭ 73 (+102.78%)
Mutual labels:  routing
arcus.messaging
Messaging with Microsoft Azure in a breeze.
Stars: ✭ 20 (-44.44%)
Mutual labels:  routing
modular routes
Dedicated controllers for each of your Rails route actions.
Stars: ✭ 45 (+25%)
Mutual labels:  routes
nuxt-i18n-routing
Localized routing with Nuxt.js
Stars: ✭ 32 (-11.11%)
Mutual labels:  routing
optimization
Routing optimization module module for Itinero.
Stars: ✭ 47 (+30.56%)
Mutual labels:  routing
angular-ssr
Angular 14 Example SSR (Server side rendering)
Stars: ✭ 92 (+155.56%)
Mutual labels:  routing
JWT-user-auth-API-bolilerplate
Boilerplate for backend API user authentication with JWT
Stars: ✭ 13 (-63.89%)
Mutual labels:  routing

Build Status

urltree

Named URL data structure with support for URL building.

Install

$ npm install urltree

Define URLs

var urltree = require('urltree');

var urls = urltree({
  'user': '/user/:id',
  'file.download': '/product/:product/download/:file',
  'repo.commit.ref': '/repo/commit/:ref'
});

urls.user.toString();
'/user/:id'

urls.file.download.toString();
'/product/:product/download/:file'

urls.repo.commit.ref.toString();
'/repo/commit/:ref'

Build URLs

urls.user.build({id: 123});
'/user/123'

urls.user.build()
// Error: URL build failed. No param id (/user/:id)

urls.file.download.build({product: 'acme', file: 'logo.jpg'});
'/product/acme/download/logo.jpg'

urls.repo.commit.ref.build({ref: 'HEAD^'});
'/repo/commit/HEAD^'

urls.repo.commit.ref.build({ref: 'HEAD^'}, true);
'/repo/commit/HEAD%5E'

Express 3

var express = require('express');
var urltree = require('urltree');

var urls = urltree({
  'user': '/user/:id'
});

var app = express();

app.get(urls.user, function(req, res) {
  res.send(urls.user.build({id: 123}));
});

Express 4

// ...

app.route(urls.user).get(function(req, res) {
  res.send(urls.user.build({id: 123}));
});

Express + Handlebars

var express = require('express');
var hbs = require('hbs');
var urltree = require('urltree');

var app = express();

var urls = urltree({
  'user': '/user/:id'
});

var engine = hbs.create();
engine.registerHelper('route', urls.handlebarsHelper);
app.engine('hbs', engine.__express);
app.set('views', '/path/to/views/');

app.use(function(req, res, next) {
  res.locals.urls = urls;
  next();
});

app.get(urls.user, function(req, res) {
  res.render('user');
});
{{route urls.user id=123}}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].