Skip to content

Get data

ts
import { ResponseContract, 
useRouteBuilder
} from "@duplojs/http";
import {
DPE
} from "@duplojs/utils";
useRouteBuilder
("POST", "/users/{userId}")
.
extract
({
params
: {
userId
:
DPE
.
coerce
.
number
(),
},
query
: {
someValue
:
DPE
.
string
().
optional
(),
superQuery
:
DPE
.
coerce
.
number
(),
}, }) .
extract
({
headers
: {
token
:
DPE
.
string
(),
},
body
:
DPE
.
object
({
username
:
DPE
.
string
(),
age
:
DPE
.
string
(),
}), }) .
handler
(
ResponseContract.
noContent
("someInformation"),
(
floor
, {
response
}) => {
const {
someValue
,
superQuery
,
token
,
userId
,
body
: {
username
,
age
,
}, } =
floor
;
return
response
("someInformation");
}, );

To retrieve data from a request, call the extract method on the route builder. This adds a data extraction step to your route. This extraction step always uses a dataParser from the @duplojs/utils library. This validates the data before you use it.

The data is then available in the Floor, an object that contains the accumulated data for the route. Data can come from extraction steps or other steps like checkers, processes, cuts, etc.

Extraction depth

ts
import { 
useRouteBuilder
} from "@duplojs/http";
import {
DPE
} from "@duplojs/utils";
useRouteBuilder
("POST", "/users/{userId}")
.
extract
({
headers
: {
token
:
DPE
.
string
(),
},
body
:
DPE
.
object
({
username
:
DPE
.
string
(),
age
:
DPE
.
string
(),
}), });

Data extraction can be done at two levels. The storage key will be the dataParser key.

Released under the MIT License.