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

Pass payload through serializer? #41

Closed
adambedford opened this issue Mar 15, 2018 · 6 comments
Closed

Pass payload through serializer? #41

adambedford opened this issue Mar 15, 2018 · 6 comments

Comments

@adambedford
Copy link

adambedford commented Mar 15, 2018

I have a non-REST endpoint users/invite and I'm trying to figure how to use this library to send a payload to that endpoint using JSONAPI format. My Application serializer uses JSONAPISerializer from ember-custom-actions already (I'm using this library in a couple other places already).

I'd like user.invite() to behave the same as user.save() in the sense that the User model is serialized (JSONAPI format) and sent as params to the endpoint.

On my User model, I have the following property:

invite: resourceAction("invite", { method: "POST" })

and in my invite action, I'm doing this:

invite(user) {
  user.invite(user.toJSON()).then(...)
}

The problem is that the payload doesn't pass through the ApplicationSerializer. I feel like I'm missing something obvious here!

@Exelord
Copy link
Member

Exelord commented Mar 15, 2018

Yes, if you would like use serializers and adapter you have to use customAction instead of resourceAction. It should be well documented in the readme. If it's not, give me some hints and I will improve it. :)

customAction - is avaialble in v2.0.0

@Exelord
Copy link
Member

Exelord commented Mar 15, 2018

Oh, sorry! you want to serialize your payload by the serializer. I think this is not implemented. You need to override dataForCustomAction and specify there your own payload serializing correctly a model by yourself, or model's serializer.

So that you can have pure user.invite() and all logic related to it inside of the adapter

But, a... I think we are missing some serializer integration to allow for custom normalization and serialization. We should try to cover it.

@Exelord
Copy link
Member

Exelord commented Mar 15, 2018

@Exelord
Copy link
Member

Exelord commented Jul 5, 2018

Feel free to reopen if needed

@Exelord Exelord closed this as completed Jul 5, 2018
@bertdeblock
Copy link

I'm also in favour of using serializers to determine the correct (JSON API) payload. This would be more in line with Ember Data. Adapters take care of the request, serializers take care of the payload.

@bertdeblock
Copy link

An additional question kind of related to this:
Is there a better way to access the model's data inside dataForCustomAction other than using store.peekRecord and params.modelId? Feels kind of hacky. For instance urlForCustomAction has a snapshot parameter that can be used.

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

No branches or pull requests

3 participants