Skip to content

Commit

Permalink
fix(ctx): adjust default value examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed May 8, 2024
1 parent 2bd5e65 commit 5dcad89
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions docs/rest-api-application/request-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ Retrieve only one value per call from the request body:
Route.post('/welcome/:id', ({ request }) => {
const defaultValue = 'defaultValue'

console.log(request.input('hello'), 'found') // 'world'
console.log(request.input('not-found'), defaultValue) // 'defaultValue'
console.log(request.input('hello', 'found')) // 'world'
console.log(request.input('not-found', defaultValue)) // 'defaultValue'

console.log(request.payload('hello'), defaultValue) // 'world'
console.log(request.payload('not-found'), defaultValue) // 'defaultValue'
console.log(request.payload('hello', defaultValue)) // 'world'
console.log(request.payload('not-found', defaultValue)) // 'defaultValue'

/*....*/
})
Expand Down Expand Up @@ -203,14 +203,14 @@ value if the first argument key doesn't exist:
Route.post('/welcome/:id', ({ request }) => {
const defaultValue = 'defaultValue'

console.log(request.param('id'), defaultValue) // '1'
console.log(request.param('not-found'), defaultValue) // 'defaultValue'
console.log(request.param('id', defaultValue)) // '1'
console.log(request.param('not-found', defaultValue)) // 'defaultValue'

console.log(request.query('world'), defaultValue) // 'hello'
console.log(request.query('not-found'), defaultValue) // 'defaultValue'
console.log(request.query('world', defaultValue)) // 'hello'
console.log(request.query('not-found', defaultValue)) // 'defaultValue'

console.log(request.header('content-type'), defaultValue) // 'application/json'
console.log(request.header('not-found'), defaultValue) // 'defaultValue'
console.log(request.header('content-type', defaultValue)) // 'application/json'
console.log(request.header('not-found', defaultValue)) // 'defaultValue'

/*....*/
})
Expand Down Expand Up @@ -400,8 +400,6 @@ Route.get('/welcome', ({ response }) => {
})
```



### The data object

Use the `data` object to define properties that will be available
Expand Down

0 comments on commit 5dcad89

Please sign in to comment.