1- [ ![ Stories in Ready] ( https://badge.waffle.io/inaka/cowboy-trails.png?label=ready&title=Ready )] ( https://waffle.io/inaka/cowboy-trails )
2-
31<img src =" https://lh5.googleusercontent.com/-Y1n1Vh4FjLE/TXDZiQ_zSVI/AAAAAAAAAJY/h47az_0MxO0/s1600/Western+backdrop+04.png " height =" 200 " width =" 100% " />
42
53# cowboy-trails
97Cowboy routes on steroids!
108
119## Contact Us
10+
1211If you find any ** bugs** or have a ** problem** while using this library, please
13- [ open an issue] ( https://github.com/inaka/elvis /issues/new ) in this repo
14- (or a pull request :) ).
12+ [ open an issue] ( https://github.com/inaka/cowboy-trails /issues/new ) in this repo
13+ (or a pull request 😄 ).
1514
16- And you can check all of our open-source projects at [ inaka.github.io] ( http://inaka.github.io ) .
15+ And you can check out all of our open-source projects at [ inaka.github.io] ( http://inaka.github.io ) .
1716
1817## Why Cowboy Trails?
19- ** Cowboy-Trails** enables you to:
2018
21- * Add information to ` cowboy ` routes, which can be used later to interact with
22- the server in a higher abstraction level.
19+ ** Cowboy-Trails** enables you to:
2320
24- * Define the server routes directly within the module that implements them.
21+ * add information to ` cowboy ` routes, which can later be used to interact with
22+ the server in a higher abstraction level,
23+ * define the server routes directly within the module that implements them.
2524
2625## How to Use it?
27- The first use case for ` cowboy_trails ` is to compile ` cowboy ` routes.
26+
27+ The most common use case for ` cowboy_trails ` is to compile ` cowboy ` routes.
2828
2929Normally with ` cowboy ` you compile routes in the following way:
3030
@@ -38,18 +38,18 @@ Routes = [{'_',
3838cowboy_router :compile (Routes ),
3939```
4040
41- Trails is also fully compatible with ` cowboy ` routes, so you can pass the same
42- routes in order to be processed by trails :
41+ Trails is fully compatible with ` cowboy ` routes, so you can pass the same
42+ routes in order to be processed by Trails :
4343
4444``` erlang
4545trails :compile (Routes ),
4646```
4747
48- So far it seems like there is not any difference, right? But the most common case
49- with ` cowboy ` is that you usually work with a single host, even though you're
48+ So far it seems like there's no difference, right? But most of the time,
49+ with ` cowboy ` , you usually work with only a single host, but you're
5050required to keep defining the host parameter within the routes (` [{'_', [...]}] ` ).
5151
52- Well, with trails you have another useful function to compile single host routes:
52+ Well, with Trails you have another useful function to compile single host routes:
5353
5454``` erlang
5555% % You only define the routes/paths
@@ -59,13 +59,15 @@ Routes = [ {"/resource1", resource1_handler, []}
5959trails :single_host_compile (Routes ),
6060```
6161
62- Now, let's suppose that you want to add additional information (metadata) to
63- cowboy routes related with the semantics of each HTTP method.
62+ Now, let's suppose you want to add metadata to
63+ ` cowboy ` routes related with the semantics of each HTTP method.
64+
65+ You'd do something like:
6466
6567``` erlang
6668Metadata = #{put => #{description => " PUT method" },
67- post => #{ description => " POST method" },
68- get => #{ description => " GET method" }},
69+ post => #{description => " POST method" },
70+ get => #{description => " GET method" }},
6971Trail = trails :trail (" /" ,
7072 cowboy_static ,
7173 {private_file , " index2.html" },
@@ -75,9 +77,9 @@ Trail = trails:trail("/",
7577Metadata = trails :metadata (Trail ),
7678```
7779
78- This can be used later to generate documentation related to each endpoint.
80+ This can then be used to generate documentation related to each endpoint.
7981
80- Normally , when you work with ` cowboy ` you have to define all routes in one place:
82+ Also , when you work with ` cowboy ` , you have to define all routes in one place:
8183
8284``` erlang
8385Routes =
@@ -100,9 +102,10 @@ Routes =
100102Dispatch = cowboy_router :compile (Routes ),
101103```
102104
103- But now with ` trails ` you're able to define the routes on each resource handler.
104- The handler must implement the callback ` trails/0 ` or ` trails/1 ` and return the specific
105- routes for that handler. For a better understanding, you can check out the
105+ But now, with ` trails ` , you're able to define the routes on each of your resource handlers,
106+ separately.
107+ These handlers must implement callback ` trails/0 ` or ` trails/1 ` and return the specific
108+ routes that define them. For a better understanding, you can check out the
106109examples in the ` test ` folder ([ trails_test_handler] ( ./test/trails_test_handler.erl ) ).
107110
108111Once you have implemented the ` trails/0 ` or ` trails/1 ` callback on your handlers, you can do
@@ -128,26 +131,10 @@ Trails =
128131trails :single_host_compile (Trails ),
129132```
130133
131- This way each handler keeps their own routes, as it should be, and you can
134+ This way each handler maintains their own routes, as it should be, and you can
132135merge them easily.
133136
134137## Example
135138
136139For more information about ` cowboy_trails ` , how to use it and the different
137- functions that it exposes, please check this [ Example] ( ./example ) .
138-
139- ## Testing
140-
141- This project's test suites include [ meta testing] ( http://inaka.net/blog/2015/11/13/erlang-meta-test-revisited/ ) .
142- Therefore, in order to run the tests, it requires a proper plt.
143- Otherwise, when you try ` rebar3 ct ` , you'll get an error similar to:
144-
145- ``` erlang
146- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147- ktn_meta_SUITE :dialyzer failed on line 60
148- Reason : {test_case_failed ,No plts at ../ ../* .plt - you need to at least have one }
149- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150- ```
151-
152- To generate the required plt, just run ` rebar3 dialyzer ` once and then you can
153- run ` rebar3 ct ` as many times as you like.
140+ functions that it exposes, please check this [ example] ( ./example ) .
0 commit comments