DoneJS StealJS jQuery++ FuncUnit DocumentJS
4.3.0
5.0.0 3.13.1 2.3.35
  • About
  • Guides
  • API Docs
  • Community
  • Contributing
  • Bitovi
    • Bitovi.com
    • Blog
    • Design
    • Development
    • Training
    • Open Source
    • About
    • Contact Us
  • About
  • Guides
  • API Docs
    • Observables
      • can-bind
      • can-compute
      • can-debug
      • can-define
      • can-define/list/list
      • can-define/map/map
      • can-define-backup
      • can-define-stream
      • can-define-stream-kefir
      • can-event-queue
      • can-kefir
      • can-list
      • can-map
      • can-map-define
      • can-observation
      • can-observation-recorder
      • can-observe
      • can-simple-map
      • can-simple-observable
      • can-stream
      • can-stream-kefir
      • can-value
    • Data Modeling
      • can-connect
      • can-connect-feathers
        • behaviors
          • ./service/
            • options
              • feathersService
            • data methods
              • createData
              • destroyData
              • getData
              • getListData
              • updateData
          • ./session/
      • can-fixture
      • can-fixture-socket
      • can-ndjson-stream
      • can-set
    • Views
      • can-component
      • can-stache
      • can-stache-bindings
      • can-stache-converters
      • can-stache-route-helpers
      • can-view-autorender
      • can-view-callbacks
      • can-view-import
      • can-view-live
      • can-view-model
      • can-view-nodelist
      • can-view-parser
      • can-view-scope
      • can-view-target
      • react-view-model
      • react-view-model/component
      • steal-stache
    • Routing
      • can-deparam
      • can-param
      • can-route
      • can-route-hash
      • can-route-mock
      • can-route-pushstate
    • JS Utilities
      • can-assign
      • can-define-lazy-value
      • can-diff
      • can-globals
      • can-join-uris
      • can-key
      • can-key-tree
      • can-make-map
      • can-parse-uri
      • can-queues
      • can-string
      • can-string-to-any
      • can-util
      • can-zone
      • can-zone-storage
    • DOM Utilities
      • can-ajax
      • can-attribute-encoder
      • can-child-nodes
      • can-control
      • can-dom-data
      • can-dom-events
      • can-dom-mutate
      • can-event-dom-enter
      • can-event-dom-radiochange
      • can-fragment
    • Data Validation
      • can-define-validate-validatejs
      • can-validate
      • can-validate-interface
      • can-validate-legacy
      • can-validate-validatejs
    • Typed Data
      • can-cid
      • can-construct
      • can-construct-super
      • can-data-types
      • can-namespace
      • can-reflect
      • can-reflect-dependencies
      • can-reflect-promise
      • can-types
    • Polyfills
      • can-symbol
      • can-vdom
    • Core
    • Infrastructure
      • can-global
      • can-test-helpers
    • Ecosystem
    • Legacy
  • Community
  • Contributing
  • GitHub
  • Twitter
  • Chat
  • Forum
  • News
Bitovi

can-connect-feathers/service/service

  • Edit on GitHub

feathersService(baseConnect)

Connects the DataInterface methods to the Feathers Service Interface methods.

connect( [
    feathersService,
    realtime
], {
    feathersService: feathersClient.service( "/api/todos" )
} );

For can-connect's real-time functionality to work with this behavior, the real-time behavior must also be included as shown in the examples.

The feathers-service behavior maps can-connect's DataInterface methods to FeathersJS's Service Interface methods.

| DataInterface method | Feathers method | HTTP method | Example Path |
|----------------------|-----------------|-------------|--------------|
| .getListData()       | .find()         | GET         | /todos       |
| .getData()           | .get()          | GET         | /todos/{id}  |
| .createData()        | .create()       | POST        | /todos       |
| .updateData()        | .update()       | PUT         | /todos/{id}  |
| not yet implemented  | .patch()        | PATCH       | /todos/{id}  |
| .destroyData()       | .remove()       | DELETE      | /todos/{id}  | 

Use

Setting up the Feathers Client is a prerequisite for using this behavior. See the can-connect-feathers page for an example of a basic Feathers Client configuration. With the Feathers client setup, it can be used with the feathers-service behavior as demonstrated in the example, below. Also note that the real-time behavior is included to receive real-time push events from the server.

// models/todo.js
import connect from "can-connect";

import DefineMap from "can-define/map/";
import DefineList from "can-define/list/list";
import set from "can-set";

// Bring in the feathers service behavior
import feathersServiceBehavior from "can-connect-feathers/service";

import dataParse from "can-connect/data/parse/";
import constructor from "can-connect/constructor/";
import constructorStore from "can-connect/constructor/store/";
import constructorCallbacksOnce from "can-connect/constructor/callbacks-once/";
import canMap from "can-connect/can/map/";
import canRef from "can-connect/can/ref/";
import dataCallbacks from "can-connect/data/callbacks/";
import realtime from "can-connect/real-time/";

// Bring in the feathersClient instance.
import feathersClient from "./feathers";

// Use feathersClient.service(url) to create a service
const todoService = feathersClient.service( "/api/todos" );

const Todo = DefineMap.extend( "Todo", {
    _id: "string",
    description: "string",
    complete: "boolean"
} );

Todo.algebra = new set.Algebra(
    set.comparators.id( "_id" )
);

Todo.List = DefineList.extend( { "*": Todo } );

Todo.connection = connect( [

    // Include the feathers service behavior in the behaviors list.
    feathersServiceBehavior,
    dataParse,
    constructor,
    constructorStore,
    constructorCallbacksOnce,
    canMap,
    canRef,

    // Include both the dataCallbacks and realtime behaviors.
    dataCallbacks,
    realtime
], {
    idProp: "_id",
    Map: Todo,
    List: Todo.List,

    // Pass the service as the `feathersService` property.
    feathersService: todoService,
    name: "todos",
    algebra: Todo.algebra
} );

export default Todo;

In the above example, both Todo and Todo.connection will have methods for handling data, as described in the basic use section.

CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 4.3.0.

On this page

Get help

  • Chat with us
  • File an issue
  • Ask questions
  • Read latest news