Is there a preferred or “Ember way” to insert an api access token?

I asked this question on StackOverflow, but maybe this would have been a better place to start.

My api expects an api token as a query parameter for GETs and DELETEs and a parameter in the body for PUT/PATCHs and POSTs.

I see in the Ember Guides the inclusion of an API key in a header, but that’s not what my api expects. I also saw some old posts that seemed to override the ajax method, but that member is marked private, so I don’t think it would be considered the “Ember Way”.

Is there a documented “Ember Way” do accomplish this? Or is there any “Best Practices” that most people are following for this?

I think overriding the ajax method would work for me, since I think the query parameters would be sent on all requests, and I think they would be available in the rails controller for GETs,POSTs,PUTs/PATCHs,DELETEs, but I hesitate to use it because it is marked as private in the documentation, although it is not named _ajax(). Are there any options on using this ajax method as described here.

Could you have the API key sent in the header?

Not without changing the api on the server side. The idea here is to adapt to the existing api, I think that’s the main idea of the adapter to begin with, right?

My recommendation is to override buildUrl

1 Like

Agreed. When you want to adapt Ember to your API, you should put all of that logic into the Adapters (and serializers if you need to). We’ve built an app with a pretty crazy API on the back-end but the whole thing “feels” like an ember app because all of the work to adapt to the API is isolated.

I will have to give buildUrl another shot, I tried this originally, but could not get it to work, so i resorted to the private ajax method.