See undici.nodejs.org for the full Undici configuration and usage.
Basic import:
// load request handler
const undici = require('@swrlab/utils/packages/undici')
// export handler
module.exports = undici()
Import with Datadog tracer enabled:
// add tracing
const tracer = process.env.DD_TRACE_ENABLED === 'true' ? require('../tracer') : null
// load request handler
const undici = require('@swrlab/utils/packages/undici')
// export handler
module.exports = undici(tracer)
Simple request:
const data = await undici(someApiUrl)
Advanced usage:
const data = await undici(someApiUrl, {
method: 'GET',
timeout: 6e3,
reject: false,
maxRedirections: 5,
})
You can also use object desctructuring for easy access to the output:
const { headers, statusCode, json } = await undici(someApiUrl)