You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/essential/path.md
+28-28Lines changed: 28 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ head:
7
7
8
8
- - meta
9
9
- name: 'description'
10
-
content: Path or pathname is an identifier to locate resources from a server. Elysia uses the path and method to look up the correct resource. Path in Elysia can be categorized into 3 types. Static, Dynamic and Wildcard.
10
+
content: A path or pathname is an identifier to locate resources of a server. Elysia uses the path and method to look up the correct resource. Paths in Elysia can be categorized into 3 types: Static, Dynamic and Wildcard.
11
11
12
12
- - meta
13
13
- property: 'og:description'
@@ -48,7 +48,7 @@ const demo4 = new Elysia()
48
48
49
49
# Path
50
50
51
-
Path or pathname is an identifier to locate resources from a server.
51
+
A path or pathname is an identifier to locate resources of a server.
52
52
53
53
```bash
54
54
http://localhost:/path/page
@@ -76,15 +76,15 @@ We can categorize the URL and path as follows:
76
76
If the path is not specified, the browser and web server will treat the path as '/' as a default value.
77
77
:::
78
78
79
-
Elysia will lookup each request for [route](/essential/route) and response using [handler](/essential/handler) function.
79
+
Elysia will look up each request for [route](/essential/route) and response using [handler](/essential/handler) function.
80
80
81
81
## Dynamic path
82
82
83
83
URLs can be both static and dynamic.
84
84
85
-
Static path means a hardcoded string can be used to locate resources from the server while dynamic path matches some part and captures the value to extract extra information.
85
+
Static paths are hardcoded strings that can be used to locate resources of the server, while dynamic paths match some part and captures the value to extract extra information.
86
86
87
-
For instance, we can extract the user ID from the pathname, we can do something like:
87
+
For instance, we can extract the user ID from the pathname. For example:
88
88
89
89
```typescript twoslash
90
90
import { Elysia } from'elysia'
@@ -95,7 +95,7 @@ new Elysia()
95
95
.listen(3000)
96
96
```
97
97
98
-
We create a dynamic path with `/id/:id` which tells Elysia to match any path up until `/id` and after it could be any value, which is then stored as **params** object.
98
+
Here dynamic path is created with `/id/:id` which tells Elysia to match any path up until `/id`. What comes after that is then stored as **params** object.
99
99
100
100
<Playground
101
101
:elysia="demo1"
@@ -120,21 +120,21 @@ When requested, the server should return the response as follows:
120
120
| /id | Not Found |
121
121
| /id/anything/rest | Not Found |
122
122
123
-
Dynamic path is great to enforce the URL to contain crucial information like ID which then can be used later.
123
+
Dynamic paths are great to include things like IDs, which then can be used later.
124
124
125
125
We refer to the named variable path as **path parameter** or **params** for short.
126
126
127
127
## Segment
128
128
129
-
URL segment is each path that is composed into a full path.
129
+
URL segments are each path that is composed into a full path.
130
130
131
-
Segment is separated by `/`.
131
+
Segments are separated by `/`.
132
132

133
133
134
134
Path parameters in Elysia are represented by prefixing a segment with ':' followed by a name.
135
135

136
136
137
-
Path parameters allow Elysia to capture a specific segment of URL.
137
+
Path parameters allow Elysia to capture a specific segment of a URL.
138
138
139
139
The named path parameter will then be stored in `Context.params`.
140
140
@@ -144,9 +144,9 @@ The named path parameter will then be stored in `Context.params`.
144
144
| /id/:id| /id/hi | id=hi |
145
145
| /id/:name| /id/hi | name=hi |
146
146
147
-
## Multiple path parameter
147
+
## Multiple path parameters
148
148
149
-
You can have as many path parameters as you would like, which will then be stored into a `params`.
149
+
You can have as many path parameters as you like, which will then be stored into a `params` object.
150
150
151
151
```typescript twoslash
152
152
import { Elysia } from'elysia'
@@ -174,7 +174,7 @@ new Elysia()
174
174
}"
175
175
/>
176
176
177
-
Requesting to the server should return the response as the following:
177
+
The server will respond as follows:
178
178
179
179
| Path | Response |
180
180
| ---------------------- | ------------- |
@@ -185,13 +185,13 @@ Requesting to the server should return the response as the following:
185
185
| /id | Not Found |
186
186
| /id/anything/rest | anything rest |
187
187
188
-
## Wildcard
188
+
## Wildcards
189
189
190
-
Dynamic path allows us to capture certain segments of the URL.
190
+
Dynamic paths allow capturing certain segments of the URL.
191
191
192
-
However, when you need a value of the path to be more dynamic and capture the rest of the URL segment, a wildcard can be used.
192
+
However, when you need a value of the path to be more dynamic and want to capture the rest of the URL segment, a wildcard can be used.
193
193
194
-
Wildcard can capture the value after segment regardless of amount by using "\*".
194
+
Wildcards can capture the value after segment regardless of amount by using "\*".
195
195
196
196
```typescript twoslash
197
197
import { Elysia } from'elysia'
@@ -218,7 +218,7 @@ new Elysia()
218
218
}"
219
219
/>
220
220
221
-
Sending a request to the server should return the response as the following:
221
+
In this case the server will respons as follows:
222
222
223
223
| Path | Response |
224
224
| ---------------------- | ------------- |
@@ -229,27 +229,27 @@ Sending a request to the server should return the response as the following:
229
229
| /id | Not Found |
230
230
| /id/anything/rest | anything/rest |
231
231
232
-
A wildcard is useful for capturing a path until a specific point.
232
+
Wildcards are useful for capturing a path until a specific point.
233
233
234
234
::: tip
235
235
You can use a wildcard with a path parameter.
236
236
:::
237
237
238
-
## Summarize
238
+
## Summary
239
239
240
240
To summarize, the path in Elysia can be grouped into 3 types:
241
241
242
-
-**static path** - static string to locate the resource
243
-
-**dynamic path** - segment can be any value
244
-
-**wildcard** - path until a specific point can be anything
242
+
-**static paths** - static string to locate the resource
243
+
-**dynamic paths** - segment can be any value
244
+
-**wildcards** - path until a specific point can be anything
245
245
246
246
You can use all of the path types together to compose a behavior for your web server.
247
247
248
-
The priority of the path is aligned as follows:
248
+
The priorities are as follows:
249
249
250
-
1. static path
251
-
2. dynamic path
252
-
3.wildcard
250
+
1. static paths
251
+
2. dynamic paths
252
+
3.wildcards
253
253
254
254
If the path is resolved as the static wild dynamic path is presented, Elysia will resolve the static path rather than the dynamic path
255
255
@@ -276,7 +276,7 @@ new Elysia()
276
276
}"
277
277
/>
278
278
279
-
Sending a request to the server should return the response as the following:
0 commit comments