payloadMethod() — fastify Function Reference
Architecture documentation for the payloadMethod() function in helper.js from the fastify codebase.
Entity Profile
Dependency Diagram
graph TD 908ea48b_b9cc_c2af_8877_19f20814593b["payloadMethod()"] f0958ec4_011b_97b2_8846_edbd37831a68["helper.js"] 908ea48b_b9cc_c2af_8877_19f20814593b -->|defined in| f0958ec4_011b_97b2_8846_edbd37831a68 style 908ea48b_b9cc_c2af_8877_19f20814593b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
test/helper.js lines 17–463
module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
const test = t.test
const fastify = require('..')()
if (isSetErrorHandler) {
fastify.setErrorHandler(function (err, request, reply) {
assert.ok(request instanceof fastify[symbols.kRequest].parent)
assert.strictEqual(typeof request, 'object')
reply
.code(err.statusCode)
.type('application/json; charset=utf-8')
.send(err)
})
}
const upMethod = method.toUpperCase()
const loMethod = method.toLowerCase()
const schema = {
schema: {
response: {
'2xx': {
type: 'object',
properties: {
hello: {
type: 'string'
}
}
}
}
}
}
test(`${upMethod} can be created`, t => {
t.plan(1)
try {
fastify[loMethod]('/', schema, function (req, reply) {
reply.code(200).send(req.body)
})
t.assert.ok(true)
} catch (e) {
t.assert.fail()
}
})
test(`${upMethod} without schema can be created`, t => {
t.plan(1)
try {
fastify[loMethod]('/missing', function (req, reply) {
reply.code(200).send(req.body)
})
t.assert.ok(true)
} catch (e) {
t.assert.fail()
}
})
test(`${upMethod} with body and querystring`, t => {
t.plan(1)
try {
fastify[loMethod]('/with-query', function (req, reply) {
req.body.hello = req.body.hello + req.query.foo
reply.code(200).send(req.body)
})
t.assert.ok(true)
} catch (e) {
t.assert.fail()
}
})
test(`${upMethod} with bodyLimit option`, t => {
t.plan(1)
try {
fastify[loMethod]('/with-limit', { bodyLimit: 1 }, function (req, reply) {
reply.send(req.body)
})
t.assert.ok(true)
} catch (e) {
t.assert.fail()
}
})
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does payloadMethod() do?
payloadMethod() is a function in the fastify codebase, defined in test/helper.js.
Where is payloadMethod() defined?
payloadMethod() is defined in test/helper.js at line 17.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free