DoneJS StealJS jQuery++ FuncUnit DocumentJS
3.14.1
5.0.0 4.3.0 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-compute
      • can-define
      • can-define/list/list
      • can-define/map/map
      • can-define-stream
      • can-define-stream-kefir
      • can-event
      • can-event/async/async
      • can-event/batch/batch
      • can-event/lifecycle/lifecycle
      • can-kefir
      • can-list
      • can-map
      • can-map-backup
      • can-map-define
      • can-observation
      • can-observe
      • can-simple-map
      • can-simple-observable
      • can-stream
      • can-stream-kefir
    • Data Modeling
      • can-connect
      • can-connect-cloneable
      • can-connect-feathers
        • behaviors
          • ./service/
            • options
              • feathersService
            • data methods
              • createData
              • destroyData
              • getData
              • getListData
              • updateData
          • ./session/
      • can-connect-ndjson
      • can-connect-signalr
      • can-fixture
      • can-fixture-socket
      • can-ndjson-stream
      • can-set
    • Views
      • can-component
      • can-ejs
      • can-element
      • can-react-component
      • can-stache
      • can-stache/helpers/route
      • can-stache-bindings
      • can-stache-converters
      • can-view-autorender
      • can-view-callbacks
      • can-view-href
      • 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-pushstate
    • JS Utilities
      • can-assign
      • can-define-lazy-value
      • can-globals
      • can-key-tree
      • can-make-map
      • can-parse-uri
      • can-string
      • can-string-to-any
      • can-util
      • can-zone
      • can-zone-storage
    • DOM Utilities
      • can-ajax
      • can-attribute-encoder
      • can-control
      • can-dom-events
      • can-event-dom-enter
      • can-event-dom-radiochange
      • can-jquery
    • 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-namespace
      • can-reflect
      • 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
var connect = require('can-connect');
var DefineMap = require('can-define/map/');
var DefineList = require('can-define/list/list');
var set = require("can-set");

// Bring in the feathers service behavior
var feathersServiceBehavior = require('can-connect-feathers/service');
var dataParse = require('can-connect/data/parse/');
var constructor = require('can-connect/constructor/');
var constructorStore = require('can-connect/constructor/store/');
var constructorCallbacksOnce = require('can-connect/constructor/callbacks-once/');
var canMap = require('can-connect/can/map/');
var canRef = require('can-connect/can/ref/');
var dataCallbacks = require('can-connect/data/callbacks/');
var realtime = require('can-connect/real-time/');

// Bring in the feathersClient instance.
var feathersClient = require('./feathers');

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

var 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
});

module.exports = 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 3.14.1.

On this page

Get help

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