I am new to ember.js and am building an app with a FastApi backend (but I don’t believe the backend that is used actually matters)
My application uses JWT token and I have created JSONAPIAdapter to use ember-data (and adds the Authorization header, specifies the query path, …)
I also need to submit some information to an API (also on the same backend) to trigger some
calculations. I am submitting an Excel file in a form and couple of test fields (so not using ember-data at all).
Is there a way that I can leverage the adapter (to get the authentication header, the path, …) or do I need to rebuild everything using a fetch in the form controller ?
The store service has an
adapterFor method which you can use to lookup any of your adapters. You could use this to pull that information out of your adapter.
In our app we have a large number of adapters, but we mostly use them for ember-data stuff, and then for the most part we make any fetch requests via a custom service we wrote for making some of that a little more ergonomic and it takes care of the headers, etc for us. We use ember simple auth and get the auth header info from the ESA session service.
That’s not to say that one way is better than the other just illustrating that there are a couple different ways you could think about making “non ember-data” requests and the right choice for you might involve a combination of factors like how many you expect to have, how conformant they will be to your adapter(s) config, and what you use for keeping authentication state, etc.
Thank you for your reply, I am also using ember simple auth and will start building my own service for my APIs.
I wanted to be sure that I am not developing something that already exists as standard functionality.
Thank you for the adapterFor hint, I’ll investigate if that one can help reducing code duplication