Skip to main content

Koa Transport

The @feathersjs/koa module provides Koa framework bindings and a REST API provider for Feathers applications.

Installation

koa()

Creates a Feathers application that extends a Koa app with Feathers functionality.

Signature

FeathersApplication
A Feathers application instance to extend with Koa functionality
Koa
A Koa application instance (defaults to new Koa())

Returns

Application<S, C>
Combined Koa and Feathers application with extended functionality including:
  • All Koa app methods and middleware
  • All Feathers service and hook capabilities
  • Enhanced listen() method that calls Feathers setup()
  • Enhanced use() method that handles both Koa middleware and Feathers services

Example

rest()

Configures the REST transport provider for Feathers services.

Signature

RestOptions | Middleware
REST configuration options or a custom formatter middleware

RestOptions

Middleware
Custom response formatter middleware
AuthenticationSettings
Authentication configuration for parsing credentials from HTTP requests

Example

parseAuthentication()

Middleware that parses authentication credentials from HTTP headers.

Signature

AuthenticationSettings
Authentication parsing configuration

AuthenticationSettings

string
Name of the authentication service
string[]
Array of authentication strategy names to parse

Example

authenticate()

Koa middleware for authenticating requests.

Signature

string | AuthenticationSettings
Authentication service name or settings object
string[]
Authentication strategies to use

Example

Exported Koa Utilities

The module exports commonly used Koa utilities:

bodyParser Options

CORS Configuration

Static File Serving

Service Options

Koa-specific service options can be configured when registering services:
Middleware[]
Middleware to run before the service handler
Middleware[]
Middleware to run after the service handler

Context Extensions

The Koa context object is extended with Feathers-specific properties:
Params
Feathers params object containing provider, headers, and other metadata
RouteLookup
Service route lookup information
HookContext
The hook context from the service call

Middleware Type

Koa middleware in Feathers uses the following type signature:

Complete Example