reanahub / reana-ui

REANA UI frontend
http://reana-ui.rtfd.io
MIT License
4 stars 33 forks source link

ui: centralize all API calls in a client file #46

Closed mvidalgarcia closed 3 years ago

mvidalgarcia commented 4 years ago

We need to decide whether to use Web API's fetch or axios to perform the calls.

mvidalgarcia commented 4 years ago

Related https://github.com/reanahub/reana-ui/issues/19

audrium commented 4 years ago

I've refactored some of the actions which were using fetch to axios in this PR: https://github.com/reanahub/reana-ui/pull/120

Here is one of the functions which were refactored:

IMO axios biggest advantage is that it allows to write less verbose code. Also if the response is not 200, it is easy to catch it as an error while with fetch you have to check if response status not ok and throw an error by yourself which leads to verbose code.

From Mozzila Fetch API docs: "An accurate check for a successful fetch() would include checking that the promise resolved, then checking that the Response.ok property has a value of true." Link: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

I'd vote to centralize API calls using axios

mvidalgarcia commented 4 years ago

@audrium: I guess we need to migrate the remaining actions to axios and plug the errorActionCreator to notify the users when some issue appears

Posted on Mattermost.

mvidalgarcia commented 4 years ago

Migration to axios done here. It's missing the centralization of all api calls in a single file (client.js) to avoid repetition and keep all URLs there. It can be a class with meaningful methods that then can be called something like Client.getWorkflows(), Client.loadConfig(), etc.