I don't know if it ever would, but if my server responded with HTTP status code 304, would the Fetch API (specifically response.ok
) and axios.get()
see the response as 200?
The documentation for both talk about the request being viewed as successful if the response code is in the range 200-299, but clearly 304 is outside this.
To send data, fetch() uses the body property for a post request to send data to the endpoint, while Axios uses the data property. The data in fetch() is transformed to a string using the JSON. stringify method.
Axios has the ability to intercept HTTP requests. Fetch, by default, doesn't provide a way to intercept requests. Axios has built-in support for download progress. Fetch does not support upload progress.
Yes, Axios use XMLHttpRequest under the hood and jQuery. ajax() wraps XMLHttpRequest too. The native way to do request is with Fetch or directly with XMLHttpRequest/XmlHttpRequest2.
When a browser does a GET request with a If-Match
or If-Modified-Since
header, and the server responds with 304 Not Modified
, the client will just see this as 200 OK
.
The response is served from cache, instead of the server, and it allows the client (axios in your case) to not have to understand HTTP caching, but it can still take advantage of it.
I don't know what a client will do when they send a request without preconditions and still get a 304
response. A client wouldn't have an earlier cached response so this would definitely be 'broken'. I'd imagine you'd get an error but I'd be curious to see what.
No, they will both not see the response as 200.
While axios.get will return a promise rejection, the return value of response.ok
when using fetch API will be false
and response.redirected
will be true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With