Whether using isPost and isGet checks seems like overkill depends on the specific context and needs of your application. However, generally speaking, these checks are considered a best practice in web development for several reasons:
-
Intent Clarification: By explicitly checking for request types, you make your code intentions clear: for example, GET requests are typically intended for retrieving data, while POST requests are for submitting or modifying data. This adheres to HTTP method conventions and ensures that your application responds correctly to different types of requests.
-
Security: Explicitly handling request types can help prevent unintended actions, such as processing data submission when it's not expected or intended. It forms a part of a broader strategy to secure your application, particularly in avoiding vulnerabilities like Cross-Site Request Forgery (CSRF).
-
Maintenance: As your application evolves, maintaining clear and explicit request handling logic can aid in debugging and feature enhancements. Code that is explicit about its operations and conditions is often easier to maintain.
In your specific example with re-fetching the user data after a POST request, if the primary goal is to ensure data consistency after a modification, it might not be overkill if you foresee scenarios where the user data could change outside of your application’s immediate control. However, if data changes are always controlled and predictable, you might consider whether this step is necessary, balancing between efficiency and the need for consistency.
In general, adding these checks doesn’t usually introduce significant complexity or overhead in your application and follows a principle of clear, predictable application behavior. However, every application has its unique context, so assess whether these practices align with your specific requirements and resource constraints.
In summary, while it might seem like overkill in very simple applications, employing these checks is usually recommended for clarity, security, and maintainability, especially as your application grows in complexity.