Skip to content

Discussion: Integrating with ember-data-url-templates #100

Description

@amiel

Hi, I'd love for ember-api-actions and ember-data-url-templates to work well together.

TLDR; I'm using this change ActionSprout@4ac52a3, and am wondering if you'd like to support this use case.

Motivation

I use ember-data-url-templates in projects where I either have no control over the api or have to support more complex urls for backwards compatibility. I'd like to also be able to use ember-api-actions in these projects, and use it in an elegant way.

Current Issue

Currently, it is possible to use ember-api-actions with ember-data-url-templates, as long as the resulting url for the api action fits under the format {urlFromTemplate}/{pathFromMemberAction}.

For example:

{
  // model
  ripen: memberAction({ path: 'ripen' }),
  // adapter
  urlTemplate: "/fruits{/id}",
}

// result
model.ripen() // PUT /fruits/1/ripen

However, some scenarios don't work quite as well:

{
  // model
  ripen: memberAction({ path: 'ripen' }),
  // adapter
  urlTemplate: "/fruits{/id}.json",
}

// result
model.ripen() // PUT /fruits/1.json/ripen

Workarounds

The neat thing is that with no changes to either library urlType can be used to configure the url template:

{
  // model
  ripen: memberAction({ path: 'ripen.json', urlType: 'ripen' }),
  // adapter
  urlTemplate: "/fruits{/id}.json",
  ripenUrlTemplate: "/fruits{/id}",
}

// result
model.ripen() // PUT /fruits/1/ripen.json

One solution

More ideal, I think, would be to not pass a path in memberAction, and instead allow the url template to control the entire url. However this causes an error, as path is required:

{
  // model
  ripen: memberAction({ urlType: 'ripen' }),
  // adapter
  urlTemplate: "/fruits{/id}.json",
  ripenUrlTemplate: "/fruits/{id}/ripen.json",
}

// result
model.ripen() // error: You must provide a path for instanceOp

Note: I am currently using this configuration with this change ActionSprout@4ac52a3

I imagine that the assert would be important in cases without url templates, so I'm not sure if this would be a good change for all users...

Moving Forward

While I have something working for my current needs, I'd like to set up the best (easy to use and straight forward) integration between ember-api-actions and ember-data-url-templates as possible. If you think my current workaround is a good direction, I'm happy to make a pull-request (with actual tests and less nested ifs). Otherwise, let's discuss. How could it be better?

What are your thoughts?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions