DEV Community

Discussion on: dev.to API - returning 404 permanently once received it once.

Collapse
 
djuber profile image
Daniel Uber

Yes, and I can replicate that as well now.

I fetched one more than the maximum id, received a 404, then was able to view it in the browser using the api endpoint (the user now existed), and from another http client on the command line, but still get a 404 in the api client I made the first request with.

If I change user agents the issue goes away. I suspect a caching layer (I see varnish in the response headers?) is capturing enough "unique" information about your request to re-serve the last copy.

I was able to work around this by adding a ?name=x query to the request (user id is made up in this example):

GET https://dev.to/api/users/123123
=> 404
// Via: 1.1 vegur, 1.1 varnish, 1.1 varnish
// X-Served-By: cache-den8243-DEN, cache-pwk4962-PWK
// X-Cache: MISS, HIT

GET https://dev.to/api/users/123123?name=x
=> 200 with json body of user 123123
// Via: 1.1 vegur, 1.1 varnish, 1.1 varnish
// X-Served-By: cache-den8243-DEN, cache-pwk4962-PWK
// X-Cache: MISS, MISS
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
grahamthedev profile image
GrahamTheDev

Interesting I did try adding a random parameter on the end of the string and it didn’t work, I will revisit that idea and send random user agent strings and see if that then works!

Thanks so much for looking at it (and I am glad it was not just me!) I will let you know if and when it works! ❤️

Thread Thread
 
grahamthedev profile image
GrahamTheDev

P.s congrats at joining the dev.to / forem team!

Thread Thread
 
djuber profile image
Daniel Uber

Thanks! It's great to be here.

Since this looks like an unwanted api behavior, I copied it over to forem's github tracker (github.com/forem/forem/issues/13293).

Also (though it doesn't help your script directly) it looks like the cached 404 response does expire automatically, maybe after 1 hour.