Skip to content

Commit 92b3c26

Browse files
committed
Added some simple docs on how to use Join and Parameters
1 parent 47a4528 commit 92b3c26

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
== Create your first URL-mapping
2+
3+
Rewrite is an extremely versatile library, but the most common use-case is to perform URL-routing, mapping, or URL-rewriting for simple paths and query parameters. This section will demonstrate how to effecively join external URLs with internal server resources.
4+
5+
=== Using Join
6+
7+
The Join rule is a composite rule made up of several other Condition and Operation objects, an inbound URL-mapping, and an outbound URL-rewriting component. Inbound requests to "path" are forwarded "to" the internal resource:
8+
9+
[source,java]
10+
----
11+
.addRule(Join.path("/external-url").to("/internal-resource.html"))
12+
----
13+
14+
=== Adding parameters
15+
16+
Joined URLs may also contain parameters, which represent fragments of the URL "path", and query-parameters of the internal resource. This means that the following `Join`:
17+
18+
[source,java]
19+
----
20+
.addRule(Join.path("/external-url-{param}").to("/internal-resource.html"))
21+
----
22+
23+
Will result in the following mapping (example):
24+
25+
[source]
26+
----
27+
URL: Resource:
28+
"/external-url-value1" --> "/internal-resource.html?param=value1
29+
"/external-url-value2" --> "/internal-resource.html?param=value2
30+
----
31+
32+
NOTE: The parameter name is used as the name of the query parameter.
33+
34+
=== Using-parameters as conditional values:
35+
36+
Parameters may also be queried and re-used in other conditional or operational values; for instance, the following rule uses the value of the `Join` parameter to inspect local resources, and suggest an alternate URL if the requested resource does not exist:
37+
38+
[source,java]
39+
----
40+
.addRule(Join.path("/{page}").to("/files/{page}.html"))
41+
.when(Resource.exists("/files/{page}.html"))
42+
.otherwise(Redirect.to("http://example.com/search?q={page}"))
43+
----
44+
45+
For additional details about using rule parameters, please read the chapter on how to link:parameters[parameterize rules]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
== Parameterize Rules
2+
3+
Docs coming soon.

‎documentation/src/main/asciidoc/index.asciidoc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ of the framework, just skip the steps you don't need.
88
=== Getting started with Rewrite
99

1010
* link:configuration/install[Install Rewrite]
11-
* Create your first URL mapping
11+
* link:configuration/mapping[Create your first URL mapping]
1212
* link:configuration/[Anatomy of a Rewrite Rule]
1313

1414
=== Working with Rewrite

0 commit comments

Comments
 (0)