Should I Return a 200 Status Code for Invalid API Calls?

0
13
Asked By CuriousCoder42 On

Hey there! I'm currently managing multiple APIs hosted on Elastic Beanstalk, mostly built with Express.js. Generally, when an API call is invalid, I respond with a 404 status code, and if something seems off, like accessing an admin route, I return a 403 code. However, I've noticed that when spam bots hit my API with a ton of invalid requests, my environment health can drop to 'Severe' because 98.1% of those requests result in HTTP 4xx errors. Would it make sense to switch things up and return a 200 status code with an error message instead of the usual 4xx codes to avoid downgrading the environment status?

4 Answers

Answered By TechieTribe On

While it's good to keep your API functioning, using 200 status codes inappropriately creates a bad habit. If your API is for a number of users or teams, it's best to adhere to conventions to prevent confusion. If your API is only for your own team, then maybe you could explain this change to them. Bottom line: consider the implications before going against established standards.

Answered By BotBuster99 On

It's really important to stick with the correct HTTP status codes. Returning a 200 for invalid requests could mislead users about the status of their calls. It's better to block those spam bots at the source and address the underlying issue rather than masking it with a 200 status. That said, if you can't implement bot protection, consider other ways to handle this situation without compromising standard practices.

Answered By CodeCritic101 On

You really shouldn't return a 200 for invalid calls; it just goes against HTTP usage conventions. There are many valid status codes for different errors, like using 400 for bad requests or 404 for not found. Instead of just switching to a generic success code, it might be more effective to handle the spam issues properly and keep your API responses accurate.

Answered By DevDude2023 On

Going for a 200 status code as a workaround is definitely odd! But hey, I understand the desire to keep your environment healthy. Just be careful; using 200 may lead to confusion for users who expect proper error feedback. If you're having trouble with permissions for the WAF, maybe there's another way to limit the bot traffic before it reaches your server.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.