Use this file to discover all available pages before exploring further.
The Feathers client library allows you to connect to your Feathers API from any JavaScript environment, including browsers, React Native, Node.js, and other platforms. It provides the same service interface on the client as on the server.
<script type="text/javascript" src="//unpkg.com/@feathersjs/client@^5.0.0/dist/feathers.js"></script><script type="text/javascript"> const app = feathers() // Connect to the API const restClient = feathers.rest('http://localhost:3030') app.configure(restClient.fetch(window.fetch.bind(window))) // Get a service const messageService = app.service('messages') // Use the service messageService.find().then(messages => { console.log('Messages:', messages) })</script>
<script type="text/javascript" src="//unpkg.com/@feathersjs/client@^5.0.0/dist/feathers.js"></script><script src="//cdn.socket.io/4.5.4/socket.io.min.js"></script><script type="text/javascript"> const socket = io('http://localhost:3030') const app = feathers() // Connect to the API app.configure(feathers.socketio(socket)) // Get a service const messageService = app.service('messages') // Listen for real-time events messageService.on('created', message => { console.log('New message created:', message) }) // Use the service messageService.create({ text: 'Hello!' })</script>
import feathers from '@feathersjs/client'import fetch from 'node-fetch'const app = feathers()// Connect to the APIconst restClient = feathers.rest('http://localhost:3030')app.configure(restClient.fetch(fetch))// Get a serviceconst messageService = app.service('messages')// Use the serviceconst messages = await messageService.find()console.log('Messages:', messages)
import feathers from '@feathersjs/client'import { io } from 'socket.io-client'const socket = io('http://localhost:3030')const app = feathers()// Connect to the APIapp.configure(feathers.socketio(socket))// Get a serviceconst messageService = app.service('messages')// Listen for real-time eventsmessageService.on('created', message => { console.log('New message created:', message)})// Use the serviceawait messageService.create({ text: 'Hello!' })
Once connected, you can use services the same way as on the server:
const messages = app.service('messages')// Find all messagesconst allMessages = await messages.find()// Get a specific messageconst message = await messages.get(1)// Create a new messageconst newMessage = await messages.create({ text: 'Hello from the client!'})// Update a messageconst updated = await messages.patch(1, { text: 'Updated text'})// Remove a messageconst removed = await messages.remove(1)