wagtail / wagtail-autocomplete

An Autocomplete edit handler for selecting Pages, Snippets, and more.
https://wagtail-autocomplete.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
120 stars 54 forks source link

Replace 3rd party package axios with fetch #168

Closed chigby closed 10 months ago

chigby commented 10 months ago

Here, I'm removing axios and replacing it with the the built-in fetch API.

The high level changes here are:

  1. 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.
  2. 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.
  3. 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.