Below is a breakdown of the Request component which is an extended Readable stream matching official Node.js specification.
- See
> [ExpressJS]for more information on additional compatibility methods and properties. - See
> [Stream.Readable]for more information on additional native methods and properties.
| Property | Type | Description |
|---|---|---|
raw |
uWS.HttpRequest |
The underlying raw uWS Http Request instance. (Unsafe) |
app |
HyperExpress.Server |
HyperExpress Server instance this Request originated from. |
method |
String |
Request HTTP method in uppercase. |
url |
String |
path + path_query string. |
path |
String |
Request path without the query. |
path_query |
String |
Request query string without the ?. |
headers |
Object |
Request Headers from incoming request. |
cookies |
Object |
Request cookies from incoming request. |
path_parameters |
Object |
Path parameters from incoming request. |
query_parameters |
Object |
Query parameters from incoming request. |
ip |
String |
Remote connection IP. |
proxy_ip |
String |
Remote proxy connection IP. |
sign(String: string, String: secret): Signs provided string with provided secret.- Returns a
String.
- Returns a
unsign(String: signed_value, String: secret): Attempts to unsign provided value with provided secret.- Returns
Stringorundefinedif signed value is invalid.
- Returns
buffer(): Parses body as a Buffer from incoming request.- Returns
Promisewhich is then resolved to aBuffer.
- Returns
text(): Parses body as a string from incoming request.- Returns
Promisewhich is then resolved to aString.
- Returns
urlencoded(): Parses body as an object from incoming urlencoded body.- Returns
Promisewhich is then resolved to anObject.
- Returns
json(Any: default_value): Parses body as a JSON Object from incoming request.- Returns
Promisewhich is then resolved to anObjectortypeof default_value. - Note this method returns the specified
default_valueif JSON parsing fails instead of throwing an exception. To have this method throw an exception, passundefinedfordefault_value. - Note
default_valueis{}by default meaningjson()is a safe method even if incoming body is invalid json.
- Returns
multipart(...2 Overloads): Parses incoming multipart form based requests allowing for file uploads.- Returns a
Promisewhich is resolved once all of the fields have been processed.- Note you may provide an async
handlerto ensure all fields get executed after eachhandlerinvocaton has finished. - Note the returnd
Promisecan reject with one of theStringconstants below or an uncaughtErrorobject.PARTS_LIMIT_REACHED: This error is rejected when the configured Busboylimits.partslimit has been reached.FILES_LIMIT_REACHED: This error is rejected when the configured Busboylimits.fileslimit has been reached.FIELDS_LIMIT_REACHED: This error is rejected when the configured Busboylimits.fieldslimit has been reached.
- Note you may provide an async
- Overload Types:
multipart(Function: handler): Parses the incoming multipart request with the default Busboyoptionsthrough the specifiedhandler.multipart(BusboyConfig: options, Function: handler): Parses the incoming multipart request with the spcifiedoptionsthrough the specifiedhandler.- Handler Example:
(field: MultipartField) => { /* Your Code Here */}- Note this
handlercan be either a synchronous or asynchronous function. - Note HyperExpress will automatically pause and wait for your async handler to resolve on each field.
- Note this
- See
> [MultipartField]to view all properties and methods available for each multipart field. - See
> [Busboy]to view all customizableBusboyConfigoptions and learn more about the Busboy multipart parser.
- Note the body parser uses the global
Server.max_body_lengthby default. You can override this property on a route by specifying a highermax_body_lengthin the route options when creating that route. - Note HyperExpress currently does not support chunked transfer requests.
- Returns a
- See ExpressJS documentation for more properties/methods that are also implemented for compatibility.
The Request component extends an EventEmitter/Readable stream meaning your application can listen for the following lifecycle events.
- [
received]: This event will get emitted whenRequesthas completely received all of the incoming body data. - See the official
> [stream.Readable]Node.js documentation for more information.