#18 Making a Request helper/utility for sending requests to API endpoints.
Closed: Fixed 2 years ago by lbrabec. Opened 3 years ago by manishakanyal.

As of now, I can see that we're using fetch(window.env.ORACULUM_API_URL_v1 + "endpoint") at many places. I believe we should create a helper function like sendRequest(endpoint, body, queryParams, ...rest) which will be a wrapper function on the top of any request tool like fetch(in our case).
So, we'll be using the sendRequest(endpoint, body, queryParams) to send API requests instead of fetch. Though we'll be using, as of now, fetch under the hood.

How it'll be helpful?

We'll be wrapping the request logic under the wrapper function so it'll be consistent throughout our codebase.
Apart from that, in case we need to use some other tool for making API requests, we'll need to replace the fetch function with something else(for ex- Axios) in a single place instead of all occurrences of fetch throughout our code.

@lbrabec, What do you think about this?


If we go on and change the folder structure as I have mentioned in issue #8, it will be handled in the API folder structure as mentioned. The base config function for axios can be done in the same folder.

@divyanshisingh you misunderstood I believe.
In this case, we'll lose our motive of having a folder structure for different things.
Certainly, the APIs will not have this thing as it'll act like a utility and not an API handler.
API directory will contain all the API calls and not the utilities used.

Metadata Update from @lbrabec:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

2 years ago

Login to comment on this ticket.

Metadata