~pepe/trolley

f35f17a922ab5106f6e78283ee3a6bd41fada879 — Josef Pospíšil 3 years ago a3c9ee0
Tune README
1 files changed, 15 insertions(+), 10 deletions(-)

M README.md
M README.md => README.md +15 -10
@@ 1,14 1,14 @@
# Trolley 
# Trolley

General router for Janet programming language. The main idea is the path and
action to which it resolves with params as defined in routes.

## Routes

We define routes as a struct with keys which contain path with optional  params
We define routes as a struct with keys which contain path with optional params
definition and values which contain actions to which the path resolves.

Example: 
Example:

```
{"/" root


@@ 16,17 16,22 @@ Example:
 "/people/:id" people}
```

## Compiling routes 
### Parameters

Parameters are declared as Janet keyword with colon at the beginning as part of
the path.

## Compiling routes

You can compile routes' configuration from the previous part to routing table where
keys contain PEG for matching route and values contains action it resolves.
keys contain PEG for matching route and values contains action to which it resolves.
This function is mostly for internal or advanced usage of this lib.

Example:

```
(import trolley)
(trolley/compile-routes 
(trolley/compile-routes
  {"/" root
   "/home" home
   "/people/:id" people})


@@ 44,13 49,13 @@ Example:

```
(import trolley)
(def match 
  (trolley/router {"/" root "/home" home "/people/:id" people})) 
(def match
  (trolley/router {"/" root "/home" home "/people/:id" people}))
(match "/people/3")
=> (people @{:id "3"})
```

## Resolver 
## Resolver

This function returns resolving function from routes definition, which then can
be used to resolve url path for the action and parameters.


@@ 60,7 65,7 @@ Example:
```
(import trolley)
(def path-for
  (trolley/resolver {"/" root "/home" home "/people/:id" people})) 
  (trolley/resolver {"/" root "/home" home "/people/:id" people}))
(path-for people @{:id "3"})
=> "/people/3"
```