Skip to content

Commit

Permalink
update changelog, and add example for trail slash
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsoni committed May 9, 2020
1 parent 87d7685 commit 88f9c14
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.8.0

* Improve trailing slash handling. Instead of separate `nil` and `trail` constructors, all routes end with `nil`.
The trailing slash is controlled via `/?` for no trailing slash, and `//?` for trailing slash. (#111)
* No longer possible to use `nil` unless it follows a pattern. To create a route that matches no path params, ex: "/"
use `empty`. (#111)

# 0.7.3

* Allow adding new routes to existing router. (#108, @tatchi)
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@ val routes : string Routes.router = <abstr>
- : string option = None
```

#### Dealing with trailing slashes

Every route definition can control what behavior it expects when it encounters
a trailing slash. In the examples above all route definitions ended with
`/? nil`. This will result in a successful match if the route does not end in a trailing slash.

```ocaml
# let no_trail () = Routes.(s "foo" / s "bar" / str /? nil @--> fun msg -> String.length msg);;
val no_trail : unit -> int Routes.route = <fun>
# Routes.(match' (one_of [ no_trail () ]) ~target:"/foo/bar/hello");;
- : int option = Some 5
# Routes.(match' (one_of [ no_trail () ]) ~target:"/foo/bar/hello/");;
- : int option = None
```

To create a route that returns a success if there is a trailing slash, the route still needs to
end with `nil`, but instead of `/?`, `//?` needs to be used. (note the extra slash).

```ocaml
# let trail () = Routes.(s "foo" / s "bar" / str //? nil @--> fun msg -> String.length msg);;
val trail : unit -> int Routes.route = <fun>
# Routes.(match' (one_of [ trail () ]) ~target:"/foo/bar/hello");;
- : int option = None
# Routes.(match' (one_of [ trail () ]) ~target:"/foo/bar/hello/");;
- : int option = Some 5
```

More example of library usage can be seen in the [examples](./example) folder,
and as part of the [test](./test/routing_test.ml) definition.

Expand Down

0 comments on commit 88f9c14

Please sign in to comment.