This PR adds a new wrapper method sendRequest() for sending API calls/requests.
Under the hood, it's using fetch() so in case we decide to move to any other utility to send API requests like Axios, SuperAgent, etc, all we've to do is make amendments in the sendRequest() wrapper method instead of changing fetch from all files.
From now on, if we've to create a new API request, we'll have to go in the following way ->
- Create a file in /api/ if needed.
- Add the *Api() method which calls the sendRequest() method and return the same.
-Catch errors wherever we're using the *Api() method.
sendRequest() supports the following this as of now-
Where, url: is the URL where we've to make the request. method: defaults to "GET", it can be any HTTP method. body: is the body of the HTTP request in case we've to send it. queryParams: In case we've to send any URL query param. It should be an object with key-value pairs.
This PR adds a new wrapper method
sendRequest()for sending API calls/requests.Under the hood, it's using
fetch()so in case we decide to move to any other utility to send API requests like Axios, SuperAgent, etc, all we've to do is make amendments in thesendRequest()wrapper method instead of changing fetch from all files.From now on, if we've to create a new API request, we'll have to go in the following way ->
- Create a file in
/api/if needed.- Add the
*Api()method which calls thesendRequest()method and return the same.-Catch errors wherever we're using the
*Api()method.sendRequest()supports the following this as of now-Where,
url: is the URL where we've to make the request.method: defaults to "GET", it can be any HTTP method.body: is the body of the HTTP request in case we've to send it.queryParams: In case we've to send any URL query param. It should be an object with key-value pairs.