Skip to content

Commit 5ed31a8

Browse files
committed
Update path params docs
1 parent 14b4d9e commit 5ed31a8

File tree

6 files changed

+80
-23
lines changed

6 files changed

+80
-23
lines changed

docs/guide/web/openapi-docs.md

+42-9
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,50 @@ get /api/products {
9595

9696
### Path Parameters
9797

98+
Path parameters allow you to capture values from the URL path. The syntax similar to `query {}` block, you can add type validators to each parameter:
99+
98100
```py
99-
get /api/users/<id:int> {
101+
get /api/users/:id {
100102
"""
101103
Get user by ID
102-
103-
Retrieves detailed information about a specific user.
104-
105-
Parameters:
106-
id: The unique identifier of the user
107-
"""
104+
""
105+
106+
path {
107+
"""User ID (must be a valid string)"""
108+
id: str
109+
}
108110
109111
// Route implementation
110112
}
111113
```
112114
115+
You can combine multiple path parameters and add type validation:
116+
117+
```py
118+
get /users/:userId/posts/:postId {
119+
"""
120+
Get user's post
121+
"""
122+
123+
path {
124+
"""User ID (alphanumeric with minimum length)"""
125+
@string(min_len=3)
126+
userId: str,
127+
128+
"""Post ID (must be a positive integer)"""
129+
@number(min=1)
130+
postId: int
131+
}
132+
133+
// Implementation example
134+
print(f"Fetching post {path.postId} for user {path.userId}");
135+
return {
136+
"userId": path.userId,
137+
"postId": path.postId
138+
};
139+
}
140+
```
141+
113142
### Request Body
114143
115144
```py
@@ -139,7 +168,7 @@ post /api/products {
139168
You can document the responses a route might return:
140169
141170
```py
142-
get /api/orders/<id:int> {
171+
get /api/orders/:id {
143172
"""
144173
Get order details
145174

@@ -150,6 +179,10 @@ get /api/orders/<id:int> {
150179
404: Order not found
151180
403: Unauthorized access
152181
"""
182+
183+
path {
184+
id: str
185+
}
153186
154187
// Route implementation
155188
}
@@ -194,7 +227,7 @@ get /api/users {
194227
}
195228
196229
@docs(tag="Users")
197-
get /api/users/<id:int> {
230+
get /api/users/:id {
198231
"""Get user by ID"""
199232
}
200233

docs/guide/web/project.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ get /api/users {
6767
// Return all users
6868
}
6969

70-
get /api/users/<id:int> {
70+
get /api/users/:id {
7171
// Return user by ID
7272
}
7373

docs/guide/web/response.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ get /outdated {
142142
### Conditional Response
143143

144144
```js
145-
get /api/users/<id:int> {
145+
get /api/users/:id {
146+
path {
147+
id: str
148+
}
149+
146150
use std.db.pg;
147151

148152
let user = pg.query_one("SELECT * FROM users WHERE id = $1", id);

docs/guide/web/route.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ verb path [, verb path...] {
2222

2323
The `verb` is the HTTP method:
2424

25-
| Verb | Description |
26-
| --- | --- |
27-
| `get` | GET request |
28-
| `post` | POST request |
29-
| `put` | PUT request |
25+
| Verb | Description |
26+
| -------- | -------------- |
27+
| `get` | GET request |
28+
| `post` | POST request |
29+
| `put` | PUT request |
3030
| `delete` | DELETE request |
31-
| `head` | HEAD request |
31+
| `head` | HEAD request |
3232

3333
The `path` is the URL path.
3434

@@ -174,8 +174,12 @@ get /hello2 {
174174
## Path Parameters
175175

176176
```py
177-
get /hello/<name:str> {
178-
return "Hello, {name}!";
177+
get /hello/:name {
178+
path {
179+
name: str
180+
}
181+
182+
return f"Hello, {name}!";
179183
}
180184
```
181185

@@ -217,7 +221,11 @@ Value is greater than 10
217221
## Query Database with SQL
218222

219223
```py
220-
get /tweet/<id: int> {
224+
get /tweet/:id {
225+
path {
226+
id: str
227+
}
228+
221229
use std.db.pg;
222230

223231
return pg.query("SELECT * FROM tweet WHERE id = $1", id);

docs/reference/route/response.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ post /login {
242242
### No Content Response
243243

244244
```js
245-
delete /api/resource/<id:int> {
245+
delete /api/resource/:id {
246+
path {
247+
id: str
248+
}
249+
246250
delete_resource(id);
247251
return response(status_code=204); // No content
248252
}

theme/components/Landingpage/features.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ web:
156156
}
157157
filename: post.ai
158158
- code: |
159-
put /repo/<id:int> {
159+
put /repo/:id {
160160
"""Update a repository"""
161+
path {
162+
"""The repository id"""
163+
id: int
164+
}
161165
162166
@json
163167
body {
@@ -170,9 +174,13 @@ web:
170174
}
171175
filename: put.ai
172176
- code: |
173-
delete /repo/<id:int> {
177+
delete /repo/:id {
174178
"""Delete a repository"""
175179
180+
path {
181+
id: str
182+
}
183+
176184
return f"delete repo: {id}";
177185
}
178186
filename: delete.ai

0 commit comments

Comments
 (0)