Connecting to a Feathers Server

Now that we went over how to set up REST and real-time APIs on the server we can look at how you can interact with a Feathers server from various clients.

Feathers as the client

Feathers itself can be used as a universal (isomorphic) client. That means that you can easily connect to remote services and register your own client side services and hooks. The Feathers client works in the browser with any front-end framework or in non-browser JavaScript environments like React Native and other NodeJS servers.

In the Feathers client chapter we will talk about how to use Feathers as a client in different environments and get it to connect to a Feathers server via REST, Socket.io and Primus.

Direct communication

In order to communicate with a Feathers API you don't need to use Feathers as the client. A Feathers server works great with any client that can connect through HTTP(S) to a REST API or - to also get real-time events - websockets. In the chapter for direct communication we will look at how to directly communicate with a Feathers API via REST, Socket.io and Primus.

Framework support

Because it is easy to integrate, Feathers does not currently have any official framework specific bindings. Work on iOS and Android SDKs are in progress.

To give you a better idea of how the Feathers client plays with other frameworks we've written some guides in the frameworks chapter. We are adding new ones all the time! If you are having any trouble with your framework of choice, create an issue and we'll try our best to help out.

Caveats

One important thing to know about Feathers is that it only exposes the official service methods to clients. While you can add and use any service method on the server, it is not possible to expose those custom methods to clients.

In the Why Feathers chapter we discussed how the uniform interface of services naturally translates into a REST API and also makes it easy to hook into the execution of known methods and emit events when they return. Adding support for custom methods would add a new level of complexity defining how to describe, expose and secure custom methods. This does not go well with Feathers approach of adding services as a small and well defined concept.

In general, almost anything that may require custom methods can also be done by creating other services. For example, a userService.resetPassword method can also be implemented as a password service that resets the password in the create:

class PasswordService {
  create(data) {
    const userId = data.user_id;
    const userService = this.app.service('user');

    userService.resetPassword(userId).then(user => {
      // Send an email with the new password
      return sendEmail(user);
    })
  }

  setup(app) {
    this.app = app;
  }
}

results matching ""

    No results matching ""