Let’s build a real-time REST API in just a few minutes. We’ll create a messages service that automatically works via REST and WebSockets.
1
Create a new Feathers application
Use the Feathers CLI to scaffold a new application:
npm create feathers my-appcd my-app
The CLI will ask you some questions about your project setup:
Choose TypeScript or JavaScript
Select your preferred database (we’ll use Memory for this quick start)
Choose Express or Koa
Select authentication options
For your first app, select Memory database and Express as the framework. You can always change these later.
2
Start the development server
Run the development server:
npm run dev
Your Feathers API is now running at http://localhost:3030!
You should see output indicating the server started successfully. The app automatically restarts when you make changes.
3
Create your first service
Let’s create a simple in-memory service manually to understand the core concepts:
app.ts
import { feathers } from '@feathersjs/feathers'import express, { rest, json, errorHandler, notFound } from '@feathersjs/express'import { memory } from '@feathersjs/memory'// Create an Express compatible Feathers applicationconst app = express(feathers())// Parse JSON and form dataapp.use(json())// Configure REST APIapp.configure(rest())// Create a messages serviceapp.use('messages', memory({ id: 'id', startId: 1, paginate: { default: 10, max: 50 }}))// Error handlingapp.use(notFound())app.use(errorHandler())// Start the serverawait app.listen(3030)console.log('Feathers app started on http://localhost:3030')
This creates a fully functional REST API with the following endpoints:
GET /messages # Find all messagesGET /messages/:id # Get a message by IDPOST /messages # Create a new messagePUT /messages/:id # Update a messagePATCH /messages/:id # Patch a messageDELETE /messages/:id # Remove a message
Add Socket.io support to enable real-time communication:
Real-time
import { feathers } from '@feathersjs/feathers'import express, { rest } from '@feathersjs/express'import socketio from '@feathersjs/socketio'import { memory } from '@feathersjs/memory'const app = express(feathers())// Configure transportsapp.configure(rest())app.configure(socketio())// Register serviceapp.use('messages', memory())// Clients can now connect via Socket.ioawait app.listen(3030)