0.1.0 • Published 2 years ago

ember-member-actions v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ember-member-actions

build maintainability

Allow non-standard Member RESTful actions.

Standard Member CRUD rest actions are super simple in Ember

GET /animals/1
PUT /animals/1
...

But more complex actions like

PUT /animals/1/favorite

Are a little more difficult. This package aims to simplify these interactions in a modern way.

*NOTE*

This package does not include collection actions like

GET /animals/arctic

Instead we are working on an additional package that will handle this functionality more like a service.

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Installation

ember install ember-member-actions

Usage

To add a member action to your models just add the @member decorator to your function.

Quickstart

import Model, { attr } from '@ember-data/model';
import { member } from 'dummy/utils/member-action';

export default class Animal extends Model {
  @attr name;
  @attr type;
  @attr uuid;

  @member({ verb: 'PUT' })
  favorite(response) {
    // ... do something with server response
  }
}

...

const animal = this.store.findRecord('animal', 1);
animal.favorite() // => calls PUT /animals/1/favorite

Verb

Default: POST

You can set the HTTP VERB you want to using the verb option

@member(verb: 'PUT')
modelFunction(response) {
  ...
}

Path

Default: Function name

The path defaults to the name of the function. If you want to change the path you can use the path option. This will always generate a url relative to the model path.

@member(path: 'star')
favorite(response) {
  ...
}

animal.star() // => POST /animals/1/star

Contributing

See the Contributing guide for details.

Bug reports and pull requests are welcome on GitHub at https://github.com/limited-effort/ember-member-actions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The pacakge is available as open source under the terms of the Apache 2 License.

Code of Conduct

Everyone interacting in the Snfoil::Context project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the code of conduct.