Here, I'm removing axios and replacing it with the the built-in fetch API.
The high level changes here are:
Add a function httpRequest that both of our existing get and post functions can call. This function makes a GET or POST request based on whether or not it's given a body argument.
Incorporate the the axios "Interceptor" code (which applies the Django CSRF token header to any POST requests) into the httpRequest function. Fetch does not support interceptors.
Incorporate the response status code checking done by get and post into httpRequest. This was the same code in both functions, and fetch has a slightly different error handling API than axios does, so we can move that into the top level function and it should "just work" like it did before.
There are possibly more options on httpRequest than are needed by our current code, but it's there in case we need to modify properties of any requests we need to make in the future.
Here, I'm removing
axios
and replacing it with the the built-in fetch API.The high level changes here are:
httpRequest
that both of our existingget
andpost
functions can call. This function makes a GET or POST request based on whether or not it's given abody
argument.httpRequest
function. Fetch does not support interceptors.get
andpost
intohttpRequest
. This was the same code in both functions, andfetch
has a slightly different error handling API than axios does, so we can move that into the top level function and it should "just work" like it did before.There are possibly more options on
httpRequest
than are needed by our current code, but it's there in case we need to modify properties of any requests we need to make in the future.