Skip to main content

BaseResponseCode

Namespace: RA.Utilities.Core.Constants

The BaseResponseCode class is a static class within the RA.Utilities.Core.Constants package. Its primary purpose is to provide a centralized, single source of truth for common HTTP status codes used throughout your application ecosystem.

By using this class, you can replace "magic numbers" (like 404, 500, etc.) in your code with named, self-documenting constants (e.g., BaseResponseCode.NotFound, BaseResponseCode.InternalServerError).

This practice offers several key advantages:

  1. Improved Readability: Code becomes much easier to understand. StatusCode(BaseResponseCode.NotFound) is more explicit and descriptive than StatusCode(404).
  2. Consistency: It ensures that all developers and services in your ecosystem use the same integer values for the same meanings, preventing inconsistencies.
  3. Reduced Errors: It eliminates the risk of typos when writing status codes, which can lead to hard-to-find bugs.
  4. Simplified Maintenance: While HTTP status codes rarely change, having them centralized means that if you ever needed to adjust a custom code, you would only need to do it in one place.

In short, BaseResponseCode is a simple but effective tool for writing cleaner, more maintainable, and more robust API code.

Constant Values

Constant NameValueCategory
Success200Default response code for success.
BadRequest400Default response code for a bad request.
Unauthorized401CDefault response code for an unauthorized request.
Forbidden403Default response code for a forbidden request.
NotFound404Default response code for a resource not found.
Conflict409Default response code for a conflict request.
InternalServerError500Default response code for an internal server error.
ServiceUnavailable503Server Error (5xx)