Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amiel opened this issue Sep 8, 2016 · 5 comments
Open

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

amiel opened this issue Sep 8, 2016 · 5 comments

Comments

@amiel
Copy link

amiel commented Sep 8, 2016

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?

@knownasilya
Copy link
Contributor

I'd love to see this happen.

@knownasilya
Copy link
Contributor

@mike-north do you give the go ahead for the PR @amiel suggested?

@dyoganand
Copy link

Guys, any update on this??

@knownasilya
Copy link
Contributor

I mean, if someone writes the PR, it'll probably be merged..

@amiel
Copy link
Author

amiel commented Feb 15, 2017

Ok, I finally did it. Sorry for taking so long. See #144.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants