Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
You can inspect the request in any handler with c.req. It holds the HTTP request data.
Common request body types:
text/plainapplication/jsonapplication/x-www-form-urlencodedmultipart/form-data(when uploading files)
In a simple text request, you can retrieve the request body using await c.req.text()
app.post('/', async c => {
const body = await c.req.text()
})
If the request body is JSON, use await c.req.json() to parse the JSON body into an object:
app.post('/', async c => {
const body = await c.req.json()
})
For application/x-www-form-urlencoded and multipart/form-data, use await c.req.parseBody():
app.post('/', async c => {
const body = await c.req.parseBody()
})
Main properties:
| Property | Description |
|---|---|
| .path | the request path |
| .method | the request method |
| .url | the request URL (protocol, host, port, path) |
| .param(“key”) | retrieve a path parameter value, used in dynamic routes |
| .query(“key”) | retrieve a specific query string parameter value |
| .queries() | retrieve all the query string parameter values, in an array |
| .header(“key”) | retrieve a specific request header value |
In addition to those, you can use all the Request object methods and properties.
Lessons in this unit:
| 0: | Introduction |
| 1: | Your first Hono app |
| 2: | ▶︎ The Request object |
| 3: | Send a response to the client |
| 4: | Manage cookies |
| 5: | Work with HTTP headers |
| 6: | Handling redirects |
| 7: | Routing |
| 8: | JSX templates |
| 9: | Middleware |
| 10: | Hono on Node.js |