|
diff --git a/DOCS.md b/DOCS.md
|
| ... |
| 166 |
- `http.run()`: Starts the event loop. |
166 |
- `http.run()`: Starts the event loop. |
| 167 |
|
167 |
|
| 168 |
### Request Object (`req`) |
168 |
### Request Object (`req`) |
| 169 |
... |
169 |
- `req.method`: The HTTP method (e.g., `"GET"`, `"POST"`). |
|
|
170 |
- `req.path`: The requested path. |
|
|
171 |
- `req.query`: A table containing URL query parameters. |
|
|
172 |
- `req.params`: A table containing route parameters (e.g., `:id`). |
|
|
173 |
- `req.body`: The raw request body as a string. |
|
|
174 |
- `req:json()`: Parses the request body as JSON and returns a Lua table (or `nil` if invalid). |
|
|
175 |
|
|
|
176 |
### Response Object (`res`) |
|
|
177 |
- `res:status(code)`: Sets the HTTP status code (e.g., `200`, `404`). Returns `res` for chaining. |
|
|
178 |
- `res:header(name, value)`: Sets a response header. Returns `res` for chaining. |
|
|
179 |
- `res:send(body)`: Sends the response body with `text/html` content type. |
|
|
180 |
- `res:json(table)`: Serializes the table to JSON and sends it with `application/json` content type. |
| 170 |
### WebSocket Object (`ws`) |
181 |
### WebSocket Object (`ws`) |
| 171 |
- `ws:send(message)`: Sends a text message to the client. |
182 |
- `ws:send(message)`: Sends a text message to the client. |
| 172 |
- `ws:on(event, callback)`: Registers an event listener. Supported events: `"message"`, `"close"`. |
183 |
- `ws:on(event, callback)`: Registers an event listener. Supported events: `"message"`, `"close"`. |
| ... |