Request
Request
Incoming request that is passed as the first argument to the middleware (req
).
Properties
req.incomingMessage
Type: readonly http.IncomingMessage
Underlying http.IncomingMessage object. Can be used to access lower-level API of http
Node.js module.
req.originalUrl
Type: readonly string
Original URL of the incoming request.
Example value:
'http://localhost:8000/api/comments?page=1&limit=10'
req.query
Type: readonly Record<string, string | string[] | undefined>
Request search params, converted to an object.
Example value:
{ page: '1', limit: '10' }
req.body
Type: string | Record<string, any> | undefined
Incoming request body. undefined
by default. To parse req.body
, use bodyParser and formParser middlewares. If request body content type is text/plain
, req.body
is a string, otherwise - Record<string, any>
.
Example value:
{ firstname: 'John', lastname: 'Doe', email: '[email protected]', password: '123456' }
req.cookies
Type: Record<string, string> | undefined
Incoming request cookies. undefined
by default. To parse req.cookies
, use bodyParser middleware.
Example value:
{ exceeded: 'true' }
req.files
Type: Record<string, UploadedFile[]> | undefined
Incoming request uploaded files. undefined
by default. To parse req.files
, use formParser middleware.
req.headers
Type: http.IncomingHttpHeaders
Incoming request headers.
req.method
Type: HttpMethod
Method of incoming request.
req.params
Type: Record<string, string | string[]>
Request parameters, parsed from route paths (see Routing).
req.path
Type: string
Request path in this Router
:
import { LunaticServer, Router } from '@shelepuginivan/lunatic'
const app = new LunaticServer()
const router = new Router()
router.get('/some-path', (req, res) => {
console.log(req.path) // '/some-path'
res.status(204).end()
})
app.use('/router', router)
app.get('/app', (req, res) => {
console.log(req.path) // '/app'
res.status(204).end()
})
app.get('/longer/path/', (req, res) => {
console.log(req.path) // '/longer/path/'
res.status(204).end()
})
req.protocol
Type: 'http' | 'https'
Incoming request protocol.
Signature
Request can be extended with other properties. Signature: { [name: string]: unknown }