Skip to content

Commit cfa06cd

Browse files
committed
feat(docs): add request body parsing methods and bump version 💃
- Bump version from 0.2.0 to 0.3.0 - Add documentation for req.arrayBuffer() method - Add documentation for req.blob() method - Add documentation for req.formData() method - Add documentation for req.json() method - Add documentation for req.text() method - Update method reference headings from ### to ####
1 parent 3fdacd9 commit cfa06cd

2 files changed

Lines changed: 51 additions & 5 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@neabyte/deserve",
33
"description": "HTTP server with file-based routing library for Deno",
4-
"version": "0.2.0",
4+
"version": "0.3.0",
55
"type": "module",
66
"license": "MIT",
77
"exports": "./src/index.ts",

docs/core-concepts/request-handling.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function GET(req: DeserveRequest): Response {
9494

9595
## Method Reference
9696

97-
### `req.query()`
97+
#### `req.query()`
9898
Returns all query parameters as an object.
9999

100100
```typescript
@@ -103,7 +103,7 @@ const query = req.query()
103103
// Expected: { q: 'deno', limit: '10' }
104104
```
105105

106-
### `req.queries(key)`
106+
#### `req.queries(key)`
107107
Returns all values for a specific query parameter key.
108108

109109
```typescript
@@ -112,7 +112,7 @@ const tags = req.queries('tags')
112112
// Expected: ['deno', 'typescript']
113113
```
114114

115-
### `req.param(key)`
115+
#### `req.param(key)`
116116
Returns a single route parameter value.
117117

118118
```typescript
@@ -122,7 +122,7 @@ const id = req.param('id')
122122
// Expected: '123'
123123
```
124124

125-
### `req.params()`
125+
#### `req.params()`
126126
Returns all route parameters as an object.
127127

128128
```typescript
@@ -132,6 +132,52 @@ const params = req.params()
132132
// Expected: { id: '123', postId: '456' }
133133
```
134134

135+
#### `req.json()`
136+
Parse request body as JSON.
137+
138+
```typescript
139+
// POST /api/users with JSON body
140+
const body = await req.json()
141+
// Expected: { name: 'John', age: 30 }
142+
```
143+
144+
#### `req.formData()`
145+
Parse request body as form data.
146+
147+
```typescript
148+
// POST /api/users with form data
149+
const formData = await req.formData()
150+
const name = formData.get('name')
151+
// Expected: name = 'John'
152+
```
153+
154+
#### `req.text()`
155+
Get request body as raw text.
156+
157+
```typescript
158+
// POST /api/text with plain text
159+
const text = await req.text()
160+
// Expected: 'Hello World'
161+
```
162+
163+
#### `req.blob()`
164+
Get request body as binary data.
165+
166+
```typescript
167+
// POST /api/upload with file
168+
const blob = await req.blob()
169+
// Expected: Blob object
170+
```
171+
172+
#### `req.arrayBuffer()`
173+
Get request body as ArrayBuffer.
174+
175+
```typescript
176+
// POST /api/binary with binary data
177+
const buffer = await req.arrayBuffer()
178+
// Expected: ArrayBuffer object
179+
```
180+
135181
## Best Practices
136182

137183
1. **Validate parameters** - Check format and type before using

0 commit comments

Comments
 (0)