FeathersJS

website·Indexed 36 days ago

https://feathersjs.com/

An open-source real-time JavaScript framework for building service-oriented APIs. It provides a common interface for database adapters (including MongoDB, SQL via Knex, and Memory), authentication strategies (JWT, OAuth, Local, API Key), and client libraries for REST and Socket.io. FeathersJS supports JSON Schema validation via TypeBox and Ajv, and can be used both on the server and as a client with frontend frameworks like React and Vue.

Tokens
71.2K
Snippets
365
Records
481
Agent score
73%

What's inside FeathersJS

  1. Overview of FeathersJS authentication strategies

    FeathersJS provides three primary authentication strategies to secure applications and manage user identities:

    1. JWT (JSON Web Token): The core mechanism for authenticating requests. The server issues a time-limited access token (defaulting to one day) upon login, which the client must include in subsequent requests.
    2. Local Authentication: Allows users to authenticate using a registered username (typically an email) and password. This requires a database to store credentials securely.
    3. OAuth Authentication: Enables users to log in via third-party providers such as Google, GitHub, or Twitter.
  2. Overview of the FeathersJS Framework

    Feathers is a full-stack web framework designed for creating APIs and real-time applications using TypeScript or JavaScript. It is compatible with Node.js, the browser, and React Native. Feathers is designed to be backend-agnostic, supporting various databases and integrating with any frontend technology, including React, VueJS, Angular, Android, or iOS.
  3. Overview of FeathersJS Event Channels

    Event channels in FeathersJS are named groups of real-time connections. They determine which connected clients receive specific real-time events (like created, patched, or removed) and allow the server to control data volume by sending only relevant updates to specific users.

    Key Constraints:

    • Channels are only available on the server side.
    • Channels require a real-time transport (e.g., Socket.io) to be configured; they are not available for REST-only APIs.
  4. Overview of FeathersJS Hooks

    Hooks are transport-independent, service-agnostic middleware functions that can be registered around, before, after, or on error of a service method. They allow developers to chain complex workflows for permissions, validation, logging, and authentication without modifying the core service logic.
  5. Overview of FeathersJS Hooks

    Hooks are pluggable middleware functions that can be registered around, before, after, or on errors of a service method. They allow developers to implement shared functionality (e.g., validation, authorization, logging) across multiple services without modifying the original service code. Hooks are transport-independent and typically service-independent, making application logic flexible and composable.
  6. Overview of @feathersjs/schema

    @feathersjs/schema is used to define data models and dynamically resolve them. It consists of three primary components: JSON schemas for data modeling, validators for ensuring data integrity, and resolvers for dynamic property manipulation based on context.
  7. Overview of FeathersJS Authentication modules

    The @feathersjs/authentication ecosystem provides tools for implementing username/password, JWT, and OAuth (e.g., GitHub, Facebook) authentication, as well as custom mechanisms. It is an abstraction layer for authentication and does not natively handle user verification or password resets; these must be implemented manually or via third-party tools like feathers-authentication-management or Auth0.

    The core components include:

    • @feathersjs/authentication: Contains the AuthenticationService for managing strategies and tokens, the JWTStrategy for authenticated requests, and the authenticate hook to restrict service access.
    • Local authentication: For standard username/password flows.
    • OAuth authentication: For third-party providers like Google, GitHub, and Facebook.
    • Authentication client: For managing authentication state and requests on the client side.
  8. Overview of FeathersJS Resolvers

    Resolvers dynamically resolve individual properties based on a context (typically the hook context in a Feathers application). They are used for tasks such as populating associations, returning computed properties, securing queries, setting context-specific default values, removing protected properties, managing property-level permissions, and hashing passwords.
  9. Overview of Feathers schemas and resolvers

    Feathers uses schemas and resolvers to define, validate, and secure data models and types. This system is database-independent and typically consists of two parts:

    1. Schema Definition: Using TypeBox or JSON schema to ensure data validity, automatically generate TypeScript types, create typed clients, generate API documentation, and validate query string filters.
    2. Resolvers: Used to modify data based on context (usually the hook context). Common use cases include populating associations, securing queries, hiding sensitive data, managing field-level permissions, and hashing passwords.
  10. Overview of Feathers Client capabilities

    Feathers allows the same functionality on the client as on the server, meaning you can use services, hooks, and plugins. A Feathers client automatically creates services that communicate with a Feathers server via REST or WebSockets. While using the Feathers client is recommended for full functionality, it is possible to connect to a Feathers server using a standalone REST or Socket.io client without the Feathers client library.
  11. Compare Feathers and LoopBack frameworks

    Feathers and LoopBack are both frameworks built on top of Express for creating APIs that mediate between frontend clients and backend data sources.

    Key differences include:

    • Architecture: LoopBack is an MVC framework using route-based CRUD configurations. Feathers uses a service-oriented model where entities are represented by lightweight services containing CRUD methods.
    • ORM Support: Feathers supports multiple databases and ORMs. LoopBack primarily uses its built-in ORM (Juggler).
    • Environment: Feathers core is engine-agnostic and works on both client and server sides. LoopBack provides a separate built-in client.
    • Transport Layers: Feathers has official libraries for multiple transport layers (e.g., sockets, primus) in addition to REST. LoopBack relies on community libraries for similar functionality.
    • Tooling: LoopBack includes built-in ACL generation and an API explorer. Feathers achieves these via third-party libraries such as feathers-permissions and feathers-swagger.
    • Philosophy: LoopBack follows a "convention-over-configuration" approach with a larger knowledge surface area. Feathers is a lightweight library that does not enforce specific conventions on how to build service-oriented APIs.
  12. Understand the Hook Context object

    The context object provides information about the service method call. It contains both read-only and writable properties.

    Read-only properties:

    • context.app: The Feathers application object.
    • context.service: The service object the hook is running on.
    • context.path: The name/path of the service.
    • context.method: The name of the service method being called.
    • context.type: The hook type (around, before, etc.).

    Writable properties:

    • context.params: The service method call parameters. Includes query (filter), provider (e.g., 'rest', 'socketio'), and user (if authenticated).
    • context.id: The record ID (for get, remove, update, patch).
    • context.data: The data sent by the user (for create, update, patch, and custom methods).
    • context.error: The thrown error (available in error hooks).
    • context.result: The result of the service method call (available in after hooks or after await next() in around hooks).