Feathers is a powerful and flexible framework for building web apps from scratch. However, it’s not only useful for building brand new applications, Feathers can also fit into your existing stack. Today I’d briefly like to show a not well known but powerful and unique use-case: Using Feathers as a real-time proxy for your existing API.

More than a real-time backend

Real-time services and frameworks like Firebase, Horizon, Parse and Meteor provide powerful real-time application stacks. The problem is that you are mostly locked in to a specific data store and tech stack. From a high level Feathers provides the same functionality but because it acts more like a broker between existing open-source technologies, you don’t have this same lock in. Feathers is just a thin layer over top of Express that establishes RESTful HTTP and websocket communication between your backend and client application. The services concept allows to easily connect to almost any database and to implement custom endpoints as your own services.

Feathers lets you choose any backend and any frontend technology while acting as the real-time connection layer between both sides. Graphic by Marshall Thompson

Also, unlike most other frameworks Feathers does not just provide a JavaScript client library. It is the client library. In the browser or React Native you are simply building another Feathers application that just happens to connect to services on a remote server. This is pretty much the same as scaling Feathers services across different servers. You can still create local services to e.g. store data in-memory or LocalStorage, too which makes it great for managing client side application state (more about that in another post). Feathers also plays nice outside of JavaScript land. As long as your client can talk HTTP and, to get real-time updates, websockets, there is a simple and well defined interface for communicating with a Feathers API.

Proxy services

Just like Feathers can connect to a database it is also possible to implement custom services that talk to an existing API. This makes it effectively a real-time proxy between clients that connect to the Feathers server via websockets and your existing HTTP API. It could additionally also act as the authentication layer so the original API won’t have to worry about it.

Feathers can act as a real-time proxy between your existing API and websocket clients. Graphic by Marshall Thompson

With a Feathers service being a JavaScript object implementing one or more of the following methods:

Let’s create a simple example that uses the Rails API implementation of Todo-Backend (different backend implementations for the TodoMVC project) running at todo-backend-rails.herokuapp.com. We can implement each service method to pass the proper request to the remote HTTP API e.g. by using the request-promise library (a promise based wrapper of request which is easier to use with the service methods that return a promise) and then return the result. Feathers will take care of automatically sending the real-time events we need. The complete code for the Feathers application looks like this:

Now we just need to install all the dependencies and start the server:

npm install feathers feathers-rest feathers-socketio body-parser feathers-errors request-promise

node app

The todos endpoint is now available at localhost:3030/todos and we can connect to the service through websockets, REST and Feathers as the client.

Conclusion

There are a lot of interesting real-time backends out there right now but there is no reason to throw your existing API away to get real-time functionality. In this article we created a Feathers application that makes an existing Rails API real-time without having to change that API at all. Of course, Feathers can be used as a full stack solution to building powerful applications as well. If you are interested in learning more, check out the docs or come join us in Slack.