API: utils
Source:
http/utils.ts
A utility class providing static methods to standardize and send common HTTP responses (success and error) with application/json content type.
Classes
HttpUtils
Provides convenient static methods for sending standard HTTP responses.
All responses are automatically formatted as 'application/json'.
Methods
sendResponseOk
sendResponseOk (entity:any):voidSends a successful response with HTTP status 200 (OK).
The provided entity is serialized as the JSON response body.
@param entity The data entity to return in the response body.
sendResponseCreated
sendResponseCreated (entity:any):voidSends a successful response with HTTP status 201 (Created).
Typically used after a resource has been successfully created.
@param entity The data entity of the newly created resource.
sendResponseNoContent
sendResponseNoContent ():voidSends a successful response with HTTP status 204 (No Content).
Typically used for successful DELETE requests or updates that do not return a body.
sendResponseBadRequest
sendResponseBadRequest (message:string):voidSends an error response with HTTP status 400 (Bad Request).
Used when the request could not be understood or processed due to client-side errors (e.g., validation failure).
@param message A descriptive error message explaining why the request was invalid.
sendForbiddenRequest
sendForbiddenRequest (message:string):voidSends an error response with HTTP status 403 (Forbidden).
Used when the client is authenticated but does not have the necessary permissions to access the resource.
@param message A descriptive error message.
sendResponseNotFound
sendResponseNotFound (message:string):voidSends an error response with HTTP status 404 (Not Found).
Used when the requested resource could not be found.
@param message A descriptive error message.
sendInternalServerError
sendInternalServerError (message:string):voidSends an error response with HTTP status 500 (Internal Server Error).
Used for unexpected server-side conditions encountered during processing.
@param message A descriptive error message (should mask internal details in production).
sendResponse
sendResponse (status:number, body?:any):voidGeneric private method to set the response status, content type, and body.
If a body is provided, it is stringified into JSON and written to the response.
@param status The HTTP status code to set (e.g., 200, 404, 500).
@param body The JavaScript object or string to be serialized as the response body (optional).