Skip to main content
Home
Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score94%
License
MIT
Downloads20/wk
Published2 weeks ago (0.27.0)

The core kernel functionality for Raptor.

Classes

c
BadRequest(
errors: string[],
message?: string
)

An error used primarily in 400 bad request errors.

  • errors: string[]
    No documentation available
  • status: number

    The HTTP status code associated with the error.

c

The Bun server implementation for Raptor.

  • serve(
    handler: RequestHandler,
    options?: { port?: number; hostname?: string; }
    ): void

    Start the server with the given request handler.

  • toConnInfo(
    server: BunServerHandle,
    request: Request
    ): ConnInfo | undefined

    Read the connection for a request from Bun's server handle.

c
Conflict(message?: string)

An error used primarily in 409 conflict request errors.

  • status: number

    The HTTP status code associated with the error.

c

HTTP content type negotiation service.

  • getBaseMediaType(contentType: string): string

    Extract base media type without parameters.

  • getTypeSpecificity(type: string): number

    Calculate specificity score for a media type.

  • isAcceptable(
    request: Request,
    contentType: string
    ): boolean

    Check if a content-type is acceptable based on the accept header.

  • isJsonType(contentType: string): boolean

    Check if a content type is JSON or JSON-based.

  • negotiate(request: Request): string

    Detect the most appropriate content type for a request based on headers.

  • parseAcceptHeader(header: string): string[]

    Parse Accept header and return types sorted by quality value and specificity.

c
Context(
request: Request,
response: Response,
connection?: ConnInfo
)

The context definition.

  • If the response has content type set.

  • connection: ConnInfo

    The connection the request arrived on, where the adapter supplied one.

  • error: HttpError | Error

    An error caught by the system.

  • hasContentType(): boolean

    Check if the response has a content-type set.

  • request: Request

    The current HTTP request.

  • response: Response

    The current HTTP response.

c
DefaultResponseManager(strictContentNegotiation?: boolean)

The response manager takes the response body and processes it into a valid HTTP response.

  • getTypeKey(body: any): string

    Determine the type key for a given body.

  • process(
    body: any,
    context: Context
    ): Promise<Response>

    Process a body into a valid Response object.

  • processors: Map<string, ResponseProcessor>

    All available response processors.

  • register(
    type: string,
    processor: ResponseProcessor
    ): void

    Add a new processor to the response manager.

  • Whether strict content negotiation is enabled.

c

The Deno server implementation for Raptor.

  • serve(
    handler: RequestHandler,
    options?: { port?: number; hostname?: string; }
    ): void

    Start the server with the given request handler.

  • toConnInfo(info?: DenoServeHandlerInfo): ConnInfo | undefined

    Read the connection from Deno's request info.

c

The plain text processor for HTTP responses.

  • escapeHtml(text: string): string

    Escape HTML special characters to prevent XSS.

  • generateBasicHtmlBody(error: Error & { errors?: Record<string, string[]>; }): string

    Generate a basic HTML body for the error.

  • generateErrorsList(errors?: Record<string, string[]>): string

    Generate the validation errors list if present.

  • generateHtmlContent(error: Error & { errors?: Record<string, string[]>; }): string

    Generate the main content body.

  • generateHtmlHead(title: string): string

    Generate the HTML head section.

  • Generate the CSS styles for the error page.

  • isHttpError(error: Error): error is HttpError

    Check if it's an HTTP Error.

  • process(
    body: any,
    context: Context
    ): Response

    Handle the response and process plain text if found.

  • transformResponse(
    error: Error,
    context: Context
    ): Response

    Transform the response based on request content type and accept headers.

c
Forbidden(message?: string)

An error used primarily in 403 forbidden request errors.

  • status: number

    The HTTP status code associated with the error.

c
Gone(message?: string)

An error used primarily in 410 gone request errors.

  • status: number

    The HTTP status code associated with the error.

c
Kernel(config?: Config)

The root initialiser for the framework.

  • add(middleware: Middleware): this

    Add new middleware to the container.

  • catch(handler: ErrorHandler): this

    Add custom error handling middleware.

  • config: Config

    Config which can be used to change kernel functionality.

  • errorHandler: ErrorHandler | null

    An optional custom error handler function.

  • executeMiddleware(
    context: Context,
    index: number
    ): Promise<Response | void>

    Execute a chosen middleware by index.

  • getConfig(): Config

    Get the configured kernel config.

  • getResponseManager(): ResponseManager

    Get the currently registered response manager.

  • getServerManager(): ServerManager

    Get the currently registered server manager.

  • Initialises the default kernel config.

  • internalErrorHandler(context: Context): Promise<void>

    Handle the uncaught error internally.

  • listen(): void

    Alias method for "serve".

  • middleware: Middleware[]

    The available middleware.

  • next(context: Context): Promise<void>

    Handle the processing of middleware.

  • processMiddlewareResponse(
    body: unknown,
    context: Context
    ): Promise<void>

    Process an unknown response body with HTTP context.

  • processUncaughtError(context: Context): Promise<void>

    Process an uncaught error with HTTP context.

  • registerConfigMiddleware(config: Config): void

    Register middleware defined in config.

  • registerConfigResponseProcessors(config: Config): void

    Register response processors defined in config.

  • respond(
    request: Request,
    connection?: ConnInfo
    ): Promise<Response>

    Handle an HTTP request and respond.

  • responseManager: ResponseManager

    The response manager for the kernel.

  • serve(): void

    Serve the application.

  • serverManager: ServerManager

    The server manager for the kernel.

  • setResponseManager(manager: ResponseManager): this

    Set or override the response manager for the kernel.

  • setServerManager(manager: ServerManager): this

    Set or override the server manager for the kernel.

  • use(middleware: Middleware): this

    Alias method for "add".

c
No documentation available
  • adapters: Map<string, ServerAdapter>
    No documentation available
  • Detect the runtime and return correct adapter.

  • register(
    name: string,
    adapter: ServerAdapter
    ): void

    Register a new adapter to the server manager.

  • serve(
    handler: RequestHandler,
    options?: { port?: number; hostname?: string; }
    ): void

    Start the server with the given request handler.

c
MethodNotAllowed(message?: string)

An error used primarily in 405 method not allowed request errors.

  • status: number

    The HTTP status code associated with the error.

c

The Node server implementation for Raptor.

  • authorityFor(options?: { port?: number; hostname?: string; }): string

    Build the authority to fall back to when a request carries no usable Host header.

  • fromWebResponse(
    response: Response,
    nodeResponse: NodeServerResponse
    ): Promise<void>

    Convert from web response.

  • hostFor(
    nodeRequest: NodeIncomingMessage,
    authority: string
    ): string

    Read the request authority from the Host header.

  • serve(
    handler: RequestHandler,
    options?: { port?: number; hostname?: string; }
    ): Promise<void>

    Start the server with the given request handler.

  • toConnInfo(nodeRequest: NodeIncomingMessage): ConnInfo | undefined

    Read the connection from the node socket.

  • toWebRequest(
    nodeRequest: NodeIncomingMessage,
    authority: string
    ): Request

    Convert to web request.

c
NotAcceptable(message?: string)

An error used primarily in 406 not acceptable request errors.

  • status: number

    The HTTP status code associated with the error.

c
NotFound(message?: string)

An error used primarily in 404 not found request errors.

  • status: number

    The HTTP status code associated with the error.

c

The object processor for HTTP responses.

  • process(
    body: any,
    context: Context
    ): Response

    Handle the response and process objects if found.

c
RequestTimeout(message?: string)

An error used primarily in 408 request timeout errors.

  • status: number

    The HTTP status code associated with the error.

c

The Response processor for HTTP responses.

  • process(
    response: any,
    _context: Context
    ): Response

    Handle the response and process if found.

c
ServerError(message?: string)

An error used primarily in 500 server errors.

  • status: number

    The HTTP status code associated with the error.

c

The HTML processor for HTTP responses.

  • process(
    body: any,
    context: Context
    ): Response

    Handle the response and process HTML if found.

c
Teapot(message?: string)

An error used primarily in 418 gone request errors.

  • status: number

    The HTTP status code associated with the error.

c
TooManyRequests(message?: string)

An error used primarily in 429 gone request errors.

  • status: number

    The HTTP status code associated with the error.

c
Unauthorized(message?: string)

An error used primarily in 401 unauthorized request errors.

  • status: number

    The HTTP status code associated with the error.

c
UnprocessableEntity(
errors: Record<string, string[]>,
message?: string
)

An error used primarily in 422 unprocessable entity request errors.

  • errors: Record<string, string[]>

    Validation errors keyed by field name.

  • status: number

    The HTTP status code associated with the error.

Functions

f
canonicaliseAddress(value: string): string | undefined

Canonicalise an IP address into one stable text form.

f
clientAddress(
context: Context,
trust?: Trust | TrustResolver
): string | undefined

Resolve the address of the client that made this request.

f
compileTrust(trust: Trust): TrustResolver

Compile a trust policy, validating it up front.

f
connInfoFor(
address?: string,
port?: number
): ConnInfo | undefined

Build connection details from a runtime-reported peer address.

f
kernel(config?: Config): Kernel
No documentation available

Interfaces

I

Config which can be used to change kernel functionality.

  • errorHandler: ErrorHandler | null

    The custom error handler for catching and responding to system errors.

  • hostname: string

    The hostname the kernel will use to serve the appliation.

  • middleware: Middleware[]

    Middleware stack, providing a way to add middleware to the kernel.

  • port: number

    The port the kernel will use to serve the application.

  • response: { manager?: ResponseManager; processors?: Record<string, ResponseProcessor>; }

    Response configuration, providing a way to override the kernel's response management.

  • server: { manager?: ServerManager; }

    Server configuration, providing a way to override the kernel's server management.

  • Enable strict RFC 7231 content negotiation.

I

Manages the processing of response bodies into HTTP Response objects.

  • process(
    body: any,
    context: Context
    ): Response | Promise<Response>

    Process a body into a valid Response object.

  • register(
    type: string,
    processor: ResponseProcessor
    ): void

    Register a new processor to the response manager.

I

An HTTP response body processor.

  • process(
    body: any,
    context: Context
    ): Promise<Response> | Response

    Handle the response body and process.

I
No documentation available
  • serve(
    handler: RequestHandler,
    options?: { port?: number; hostname?: string; }
    ): void | Promise<void>

    Start the server with the given request handler.

I

Manages the serving of applications.

  • register(
    name: string,
    adapter: ServerAdapter
    ): void

    Register a new adapter to the server manager.

  • serve(
    handler: RequestHandler,
    options?: { port?: number; hostname?: string; }
    ): void

    Start the server with the given request handler.

Type Aliases

T
RequestHandler = (
request: Request,
connection?: ConnInfo
) => Promise<Response>

The request handler a server adapter drives. connection is optional, as not every runtime exposes one.

T
Trust = false | number | string[]

How far to trust X-Forwarded-For when resolving a client address.

T
TrustResolver = (
address: string,
index: number
) => boolean

Decides whether the hop at index in the chain may be trusted.

Variables

v
T
ResponseBodyType: { RESPONSE: string; ERROR: string; STRING: string; OBJECT: string; }

A convenient helper for dealing with response body types.

  • ERROR: string
    No documentation available
  • OBJECT: string
    No documentation available
  • RESPONSE: string
    No documentation available
  • STRING: string
    No documentation available

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.