Used throughout the project to express "empty object"
pass the request properties that the app requires. Usually added by the middlewares
A pure function to convert an HttpContext into a HttpResponse object
An middleware that uses HttpContext and modifies it to be used by the app or the downstream middlewares
You can compose middlewares in order to build a larger app. Each middlewares would process the request parameters and add new ones, that would be available to downstream components.
const app: App = ...;
const middleware1: Middleware = ...;
const middleware2: Middleware = ...;
const appWithMiddlewares = middleware1(middleware2(app));
Specify what parameters the component would add into the HttpContext.
Specify what parameters to require from the HttpContext.
A response that can be rendered by Laminar direcrectly, and would not need to be processed. All response bodies should be converted to tbis
Deeply convert one typescript type to another, following nested objects and arrays
interface MyType {
date: Date;
}
type JsonMyTpe = Json<MyType>
// JsonMyTpe['date'] will be string
Specify what parameters the component would add into the HttpContext.
Specify what parameters to require from the HttpContext.
An middleware that uses HttpContext and modifies it to be used by the app or the downstream middlewares
You can compose middlewares in order to build a larger app. Each middlewares would process the request parameters and add new ones, that would be available to downstream components.
const app: App = ...;
const middleware1: Middleware = ...;
const middleware2: Middleware = ...;
const appWithMiddlewares = middleware1(middleware2(app));
A helper type to allow Typescript to correctly infer the types of all the previous / next middleware in the flow
A function to compose with other middlewares over an app
The authorized user, returned by OapiSecurityResolver
A HttpResponse creator helper, used for optional
Captured path parameters to the route would be passed to the path
property.
pass the request properties that the listener requires. Usually added by the middlewares
A function to check if a route matches. If it does, returns the captured path parameters, otherwsie - false.
The default header used by responseTimeMiddleware
Http body parser for anything, just concatenates the stream
Http body parser for url encoded requests (http forms)
Http body parser for json requests
Http body parser for plain text requests
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 400
The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: application/octet-stream
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: text/css
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: text/csv
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
Return a file response. Setting the 'content-type', 'content-length', 'last-modified' headers based on the file itself. Supports content ranges as well, if you pass the incommingMessage from the request, so it can determine the range.
'Content-Type' header is set by inspecting the file extention. If no match could be found, defaults to 'text/plain'.
Would set the 'Last-Modified', 'Content-Type' and 'Content-Length' headers
If you provide incommingMessage
, would set 'Last-Modified', 'Content-Type' and 'Accept-Ranges'. Also 'Content-Range' if there was a 'Range' header in the request
a local path to the file.
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 403
The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: application/x-www-form-urlencoded
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 302
Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: text/html
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and badRequest
Content-Type: text/html
Status: 400
The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and noContent No body is specified as this response should not have any content
Content-Type: text/html
Status: 201
The request has been fulfilled, resulting in the creation of a new resource.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and forbidden
Content-Type: text/html
Status: 403
The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and found
Content-Type: text/html
Status: 302
Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and internalServerError
Content-Type: text/html
Status: 500
A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and movedPermanently
Content-Type: text/html
Status: 301
This and all future requests should be directed to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and notFound
Content-Type: text/html
Status: 404
The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and ok
Content-Type: text/html
Status: 200
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and seeOther
Content-Type: text/html
Status: 303
The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and unauthorized
Content-Type: text/html
Status: 401
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.
Strictly type the response body
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 500
A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Deeply convert JS Date types to string and remove undefined values.
Content-Type: application/json
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and badRequest
Content-Type: application/json
Status: 400
The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and noContent No body is specified as this response should not have any content
Content-Type: application/json
Status: 201
The request has been fulfilled, resulting in the creation of a new resource
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and forbidden
Content-Type: application/json
Status: 403
The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and found
Content-Type: application/json
Status: 302
Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and internalServerError
Content-Type: application/json
Status: 500
A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and movedPermanently
Content-Type: application/json
Status: 301
This and all future requests should be directed to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and noContent No body is specified as this response should not have any content
Content-Type: application/json
Status: 204
The server successfully processed the request, and is not returning any content.
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and notFound
Content-Type: application/json
Status: 404
The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and ok Deeply convert JS Date types to string and remove undefined values.
Content-Type: application/json
Status: 200
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and seeOther
Content-Type: application/json
Status: 303
The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and unauthorized
Content-Type: application/json
Status: 401
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.
Strictly type the response body
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 301
This and all future requests should be directed to the given URI.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 204
The server successfully processed the request, and is not returning any content.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 404
The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 304
Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 200
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to allow optional bodies to be chained with nullish coallesing For example you can combine jsonOk and jsonNotFound
const handler = () => {
const value: MyType | undefined = ...
return optional(jsonOk, value) ?? jsonNotFound({ message: 'Not Found' });
}
Strictly type the response body, can be undefined too
Strictly type the http status value
Strictly type the http headers.
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: application/pdf
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
Create a response object that will redirect to a given location. Sets the 'Location' header.
URL the location to redirect to, would be set as the "Location" header
The type of the response body
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 303
The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
Set cookie headers on the response object
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: text/plain
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and badRequest
Content-Type: text/plain
Status: 400
The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and noContent No body is specified as this response should not have any content
Content-Type: text/plain
Status: 201
The request has been fulfilled, resulting in the creation of a new resource.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and forbidden
Content-Type: text/plain
Status: 403
The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and found
Content-Type: text/plain
Status: 302
Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and internalServerError
Content-Type: text/plain
Status: 500
A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and movedPermanently
Content-Type: text/plain
Status: 301
This and all future requests should be directed to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and notFound
Content-Type: text/plain
Status: 404
The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and ok
Content-Type: text/plain
Status: 200
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and seeOther
Content-Type: text/plain
Status: 303
The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and unauthorized
Content-Type: text/plain
Status: 401
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.
Strictly type the response body
A helper to set the status of a HttpResponse to a specific type literal constant.
Status: 401
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: application/xml
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to set the Content-Type
header of a HttpResponse to a specific type literal constant.
Content-Type: application/yaml
Strictly type the response body
A generic response, allowing us to preserve the types passed from previous helpers
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and badRequest
Content-Type: application/yaml
Status: 400
The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and noContent No body is specified as this response should not have any content
Content-Type: application/yaml
Status: 201
The request has been fulfilled, resulting in the creation of a new resource.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and forbidden
Content-Type: application/yaml
Status: 403
The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and found
Content-Type: application/yaml
Status: 302
Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and internalServerError
Content-Type: application/yaml
Status: 500
A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and movedPermanently
Content-Type: application/yaml
Status: 301
This and all future requests should be directed to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and notFound
Content-Type: application/yaml
Status: 404
The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and ok
Content-Type: application/yaml
Status: 200
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and seeOther
Content-Type: application/yaml
Status: 303
The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.
Strictly type the response body
A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and unauthorized
Content-Type: application/yaml
Status: 401
Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.
Strictly type the response body
Convert a stream of text data into a single string. If there were no chunks in the stream, return undefined
Parse a cookie header.
Parse the given cookie header string into an object The object has the various cookies as keys(names) => values
Parse a multipart body chunk, as part of the MultipartParser transform
Convert a URLSearchParams into a nested object. Supports ',' separateros as well as a[a][b] like names to build nested objects and arrays
A generic middleware that will just pass any params into the context of the function execution.
const myCtx = { testDate: new Date() };
const withTestDate = passThroughMiddleware(myCtx);
new HttpListener({
listener: withTestDate(async ({ testDate }) => {
console.log(testDate);
})
})
pass through all the params of the context as is.
pass through all the params of the context as is.
Get metadata object for loggers from an error instance
Convert a javascript object into a JSON plain object. Serializes Dates into strings and removes keys with undefined values
const a = toJson({ date: new Date(), test: undefined });
// a will be { date: '2020-01 ...' };
Converts a stream generated from multipart parser into a MultipartData object.
Start all the Service objects in initOrder
sequentially. If it has an array of Service, will start them in parallel.
// Will start s1, s2 and s3 in that sequential order
start({ initOrder: [s1, s2, s3] });
// Will start s1 and s2, then start s3, s4 and s5 in parallel, and lastly start s6
start({ initOrder: [s1, s2, [s3, s4, s5], s6] });
// Will stop s3, s2 and s1 in that sequential order
stop({ initOrder: [s1, s2, s3] });
// Will stop s6, then s3, s4 and s5 in parallel, and lastly will stop s2 and s1 sequentially
start({ initOrder: [s1, s2, [s3, s4, s5], s6] });
Parse the incommingMessage request into a javascript object
Supports contentTypes by default for:
replace with custom parsers, can use [...defaultBodyParsers, newParser] to add
Cors middleware
The default error handler, used by errorsMiddleware. Convert an error object into a json HttpResponse
Create a listener for a specific method (DEL), used by router
Catch and convert errors into error responses. By default convert to a json with the error message
use the error property to return a response object from an error
Create a listener for a specific method (GET), used by router
Check if a response from OapiSecurityResolver is a HttpError object, indicating a failed security check
Check if a response from OapiSecurityResolver is a SecurityOk object, indicating a successfull security check
Create an application using an OpenApi schema. The api can be a filename (json or yaml) or a javascript object containing OpenApi Schema. You also provide an HttpListener for each path. As well as all security resolvers
pass the request properties that the app requires. Usually added by the middlewares
Create a listener for a specific method (OPTIONS), used by router
Parse the body of HttpResponse, using content-type header and a list of parsers. Conver it to a suitable string representation
Create a listener for a specific method (PATCH), used by router
Create a listener for a specific method (POST), used by router
Create a listener for a specific method (PUT), used by router
A middleware to log the response of a request, as well as any errors
Parse the response body using the provided parsers. By default support
Track response time of a response
A generic route function. If you omit the method, would match any method.
pass the request properties that the listener requires. Usually added by the middlewares
Use different routes to call different parts of the application.
If you have route parameter in the path, like /test1/{id}
would pass them down in the path
property of the request.
const listener:App = router(
get('/route1/{id}', ({ path: { id }}) => {
// ...
}),
post('/other-route', ({ body }) => {
// ...
})
)
pass the request properties that the listener requires. Usually added by the middlewares
Return a HttpError object, indicating a faild security check. Should be returned by a OapiSecurityResolver
Return a SecurityOk object, indicating a successfull security check. Should be returned by a OapiSecurityResolver
Return a HttpError object, indicating a faild security check, to redirect to a new page Should be returned by a OapiSecurityResolver
Serialize data into a cookie header.
Serialize the a name value pair into a cookie string suitable for http headers. An optional options object specified cookie parameters.
serialize('foo', 'bar', { httpOnly: true }) => "foo=bar; httpOnly"
You can serve a directory of static assesets with staticAssets
helper.
The pathname where the directory would be located, example: '/assets'
The directory containing the files
Options
A component that parses the url and header information from the raw incommingMessage
And adding host
, protocol
, headers
, url
and method
properties
Combine all the components into a single middleware, and allow passing options to individual component
Get the multipart boundary from contentType
header from http request
boundary string or undefined, if not found
Creeate a request listner to be used for http.createServer
A HttpListener would convert an incomingRequest to a HttpResponse object. This function would also use the parameters of the HttpResponse to set the statusCode, headers and body in the Request Listener Multiple headers are supported. If the response body is a Readable Stream it would stream it as a response directly
A generic logger middleware. Can be used with any resolver funciton, like http listener or queue worker.
const withLogger = loggerMiddleware(console);
new HttpListener({
listener: withLogger(async ({ logger }) => {
logger.info('test');
})
})
Logger instance, must implement info
and error
. You can use console
to output to stdout
Bake in some metadata for each logger call afterwards, reusing the same logger instance.
Useful for adding trace tokens and the like
const myLogger = console
const myLoggerTraced = withStaticMetadata(myLogger, { traceToken: '123' });
// Would output 'trace' with the traceToken metadata we've setup earlier.
myLoggerTraced.info('test');
Generated using TypeDoc
A type to help with creating specific middlewares. Allows you to say create a middleware for a function that takes those specific arguments and returns a specific type. This is used throughout laminar to define type like and WorkerMiddleware
For example this will create a middlware type for function that would always accept
MyRequest
type.