All Projects → weavejester → Clout

weavejester / Clout

Licence: other
HTTP route-matching library for Clojure

Programming Languages

clojure
4091 projects
ring
36 projects

Labels

Projects that are alternatives of or similar to Clout

Dcompass
[WIP] High-performance programmable DNS server aiming at robustness, speed, and flexibility
Stars: ✭ 174 (-23.68%)
Mutual labels:  routing
Elefant
Elefant, the refreshingly simple PHP CMS and web framework.
Stars: ✭ 188 (-17.54%)
Mutual labels:  routing
Ui Router
The de-facto solution to flexible routing with nested views in AngularJS
Stars: ✭ 13,738 (+5925.44%)
Mutual labels:  routing
Navi
🧭 Declarative, asynchronous routing for React.
Stars: ✭ 2,069 (+807.46%)
Mutual labels:  routing
Openrouteservice App
🚙 The open source route planner app with plenty of features.
Stars: ✭ 187 (-17.98%)
Mutual labels:  routing
Atlasr
Atlasr is a truly open-source and free map browser.
Stars: ✭ 196 (-14.04%)
Mutual labels:  routing
Flow builder
Flutter Flows made easy! A Flutter package which simplifies flows with a flexible, declarative API.
Stars: ✭ 169 (-25.88%)
Mutual labels:  routing
Falco
A functional-first toolkit for building brilliant ASP.NET Core applications using F#.
Stars: ✭ 214 (-6.14%)
Mutual labels:  routing
Ataraxy
A data-driven Ring routing and destructuring library
Stars: ✭ 187 (-17.98%)
Mutual labels:  routing
Lime Packages
OpenWrt packages composing LibreMesh meta-firmware for wireless mesh networking
Stars: ✭ 204 (-10.53%)
Mutual labels:  routing
Routemagic
Utility Library to get the most out of ASP.NET Routing.
Stars: ✭ 180 (-21.05%)
Mutual labels:  routing
Fault tolerant router
A daemon, running in background on a Linux router or firewall, monitoring the state of multiple internet uplinks/providers and changing the routing accordingly. LAN/DMZ internet traffic is load balanced between the uplinks.
Stars: ✭ 182 (-20.18%)
Mutual labels:  routing
Osrm Frontend
Modular rewrite of the OSRM frontend using LRM
Stars: ✭ 197 (-13.6%)
Mutual labels:  routing
Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (-24.12%)
Mutual labels:  routing
Aqueduct
Dart HTTP server framework for building REST APIs. Includes PostgreSQL ORM and OAuth2 provider.
Stars: ✭ 2,412 (+957.89%)
Mutual labels:  routing
Vite Plugin Voie
File system based routing plugin for Vite
Stars: ✭ 172 (-24.56%)
Mutual labels:  routing
Peering Manager
Peering sessions management tool
Stars: ✭ 189 (-17.11%)
Mutual labels:  routing
Silk
Routing for Clojure & ClojureScript
Stars: ✭ 217 (-4.82%)
Mutual labels:  routing
Pushy
Clojurescript library for quick and easy HTML5 pushState
Stars: ✭ 212 (-7.02%)
Mutual labels:  routing
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+932.46%)
Mutual labels:  routing

Clout

Build Status

Clout is a library for matching Ring HTTP requests. It uses the same routing syntax as used by popular Ruby web frameworks like Ruby on Rails and Sinatra.

Installation

Add the following to your project.clj dependencies:

[clout "2.2.1"]

Usage

Require Clout in the normal way:

(require '[clout.core :as clout])

These following examples also make use of the Ring-Mock library to generate Ring request maps:

(require '[ring.mock.request :as mock])

Routes can match by keyword:

(clout/route-matches
 "/article/:title"
 (mock/request :get "/article/clojure"))

=> {:title "clojure"}

Or with wildcards:

(clout/route-matches
 "/public/*"
 (mock/request :get "/public/style/screen.css"))
 
=> {:* "style/screen.css"}

Clout can also match absolute routes:

(clout/route-matches
 "http://subdomain.example.com/"
 (mock/request :get "http://subdomain.example.com/"))

=> {}

And scheme-relative routes:

(clout/route-matches
 "//subdomain.example.com/"
 (mock/request :get "http://subdomain.example.com/"))

=> {}

(clout/route-matches
 "//subdomain.example.com/"
 (mock/request :get "https://subdomain.example.com/"))
 
=> {}

Clout supports both keywords and wildcards. Keywords (like ":title") will match any character but the following: / . , ; ?. Wildcards (*) will match anything.

If a route does not match, nil is returned:

(clout/route-matches "/products" (mock/request :get "/articles"))

=> nil

For additional performance, you can choose to pre-compile a route:

(def user-route
  (clout/route-compile "/user/:id"))

(clout/route-matches user-route (mock/request :get "/user/10"))

=> {:id "10"}

When compiling a route, you can specify a map of regular expressions to use for different keywords. This allows more specific routing:

(def user-route
  (clout/route-compile "/user/:id" {:id #"\d+"}))

(clout/route-matches user-route (mock/request :get "/user/10"))

=> {:user "10"}

(clout/route-matches user-route (mock/request :get "/user/jsmith"))

=> nil

You can also specify regular expressions inline in braces after the keyword:

(def user-route
  (clout/route-compile "/user/:id{\\d+}"))

Note that regular expression escape sequences (like \d) need to be double-escaped when placed inline in a string.

License

Copyright © 2018 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

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].