1.7.2 • Published 9 years ago

ng-feathers v1.7.2

Weekly downloads
1
License
MIT
Repository
-
Last release
9 years ago

npm Bower Travis Code Climate Gemnasium js-standard-style Beevelop

ngFeathers :bird:

:warning: Still WIP: API is unstable and might change.

FeatherJS for plain old AngularJS (1.X)

Installation

Install via Bower:

bower install --save ng-feathers

Add standalone version (dependencies included) to your HTML file

<script src="bower_components/ng-feathers/dist/ng-feathers.standalone.min.js"></script>

Or add Socket.io + Feathers-Client + (minified) ngFeathers individually:

<script src="bower_components/socket.io-client/socket.io.js"></script>
<script src="bower_components/feathers-client/dist/feathers.js"></script>
<script src="bower_components/ng-feathers/dist/ng-feathers.min.js"></script>

Install via npm:

npm install --save ng-feathers

Add standalone version (dependencies included) to your HTML file

<script src="node_modules/ng-feathers/dist/ng-feathers.standalone.min.js"></script>

Or add Socket.io + Feathers-Client + (minified) ngFeathers individually:

<script src="node_modules/socket.io-client/socket.io.js"></script>
<script src="node_modules/feathers-client/dist/feathers.js"></script>
<script src="node_modules/ng-feathers/dist/ng-feathers.min.js"></script>

REST

  • REST requires jQuery as it depends on jQuery's AJAX implementation

Usage (with Socket.io)

// Add ngFeathers as dependency
angular.module('myApp', ['ngFeathers'])

  // Optionally configure $feathersProvider
  .config(function ($feathersProvider) {
    $feathersProvider.setEndpoint('http://localhost:3030')

    // You can optionally provide additional opts for socket.io-client
    $feathersProvider.setSocketOpts({
      path: '/ws/'
    })
    
    // true is default; set to false if you like to use REST
    $feathersProvider.useSocket(true)
  })
  .controller('app', function ($feathers) {
    var userService = $feathers.service('users')

    userService.on('created', function (msg) {
      console.log(msg)
    })

    userService.create({
      username: 'john',
      password: 'unicorn'
    }).then(function (res) {
      $feathers.authenticate({
        type: 'local',
        username: 'john',
        password: 'unicorn'
      }).then(function (result) {
        console.log('Authenticated!', result)
      }).catch(function (error) {
        console.error('Error authenticating!', error)
      })
      console.log(res)
    }).catch(function (err) {
      console.error(err)
    })
  })

Provider-API

  • $feathersProvider.setAuthStorage(newAuthStorage:Object) (default: window.localStorage)
  • $feathersProvider.setSocketOpts(opts:Object) (optional)
  • $feathersProvider.useSocket(socketEnabled:Boolean) (default: true)
  • $feathersProvider.setEndpoint(newEndpoint:String)

Service-Functions (stolen from the official FeatherJS Docs)

  • find({query: {attr: 'value'}}): Retrieves a list of all matching resources from the service
  • get(id, {query: {fetch: 'all'}}): Retrieve a single resource from the service.
  • create({"text": "Example"}): Create a new resource with data which may also be an array.
  • update(id, {"text": "Example"}): Completely replace a single or multiple resources.
    • ProTip: update is normally expected to replace an entire resource which is why the database adapters only support patch for multiple records.
  • patch(id, {"text": "Example"}): Merge the existing data of a single or multiple resources with the new data.
  • remove(id): Remove a single or multiple resources:
1.7.2

9 years ago

1.6.1

10 years ago

1.6.0

10 years ago

1.5.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago