Best way to call backend api
-
Could you please let me know what is the best way to call backend api from quasar ? Is there any design pattern we can follow ? How can reuse the return object in multiple pages once api is called ?
-
What is your backend supporting? Rest? GraphQL?
Scott
-
@arkaprova You can use axios for POSTing and GETting backend API and wrap the response into JSON file containing
{ status: true/false, data: { key1: value1, key2: value2, etc. } }
Status can be specified as codes instead, like status: 200 | status: 400 | etc.
Data can be string | array | object | numberThat all would really depend on how you read the requests and return the values in backend.
-
@s-molinari Rest api
-
I personally like using the fetch api, but axios works too. As far as how I structure it, I usually have a boot file that injects an instance of a class into
Vue.prototype.$api
so I can call it anywhere likethis.$api.getUsers()