Skip to main content

What are Services?

Services are the core building blocks of a Feathers application. A service is simply an object or class that implements one or more of the standard service methods for CRUD operations.

Service Methods

Feathers services can implement the following standard methods:
  • find(params) - Retrieve multiple records
  • get(id, params) - Retrieve a single record by ID
  • create(data, params) - Create one or more records
  • update(id, data, params) - Replace a record
  • patch(id, data, params) - Merge data into a record
  • remove(id, params) - Remove a record

Creating a Basic Service

The simplest way to create a service is with an object that implements service methods:
Service methods must be async or return a Promise. Synchronous methods are not supported.

Registering Services

Register services with your application using the app.use() method:
1

Choose a Path

The first argument is the service path - this will be the endpoint for your service:
2

Provide the Service

The second argument is your service object or class instance:
3

Add Service Options (Optional)

The third argument allows you to configure service behavior:

Accessing Services

Once registered, access services using app.service():
Accessing Services

Service Parameters

All service methods receive a params object as their last argument. This object can contain:
  • query - Query parameters for filtering, sorting, pagination
  • user - The authenticated user (if using authentication)
  • provider - The transport used (rest, socketio, etc.)
  • Custom properties added by hooks or middleware
Using Parameters

Memory Service

Feathers provides a built-in in-memory service adapter for prototyping and testing:
Memory Service

Database Adapters

Feathers provides adapters for popular databases that implement all service methods:

Service Options

When registering a service, you can configure its behavior with options:
Service Options

Default Service Events

By default, services emit events for data-modifying operations:
  • created - After create()
  • updated - After update()
  • patched - After patch()
  • removed - After remove()
Listening to Service Events

Custom Service Methods

You can add custom methods to your services beyond the standard CRUD operations:
Custom Methods
Custom methods cannot use protected names like setup, teardown, hooks, on, emit, or any EventEmitter method names.

Service Lifecycle

Services can implement setup() and teardown() lifecycle methods:
Service Lifecycle
  • setup(app, path) - Called when the application starts or when the service is registered after startup
  • teardown(app, path) - Called when the application shuts down

Removing Services

You can dynamically remove services using app.unuse():
Removing Services

Complete Service Example

Here’s a complete example of a custom service with validation and lifecycle methods:
Complete Service Example