Reputation: 711
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.
Upvotes: 11
Views: 11850
Reputation: 99851
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.
Upvotes: 14
Reputation: 38992
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
.
Upvotes: 1