2** EPITECH PROJECT, 2024
5** speak_on_correct_status.js
8import { Response } from "express";
10export namespace SpeakOnCorrectStatus {
14 * Sends a JSON response with a given HTTP status.
15 * @param res - The Express response object.
16 * @param status - The HTTP status code (default: 200).
17 * @param json - The JSON object to send.
19 export function send_message_on_status(res: Response, status: number = 200, json: object = { 'title': '<empty>', 'msg': 'message', 'token': '' }): void {
20 res.status(status).json(json);
23 // 1xx informational response
26 * Sends a "100 Continue" response.
27 * @param res - The Express response object.
28 * @param json - The JSON object to send.
30 export function send_continue(res: Response, json: object): void {
31 return send_message_on_status(res, 100, json);
35 * Sends a "101 Switching Protocols" response.
36 * @param res - The Express response object.
37 * @param json - The JSON object to send.
39 export function switching_protocols(res: Response, json: object): void {
40 return send_message_on_status(res, 101, json);
44 * Sends a "102 Processing" response.
45 * @param res - The Express response object.
46 * @param json - The JSON object to send.
48 export function processing(res: Response, json: object): void {
49 return send_message_on_status(res, 102, json);
53 * Sends a "103 Early Hints" response.
54 * @param res - The Express response object.
55 * @param json - The JSON object to send.
57 export function early_hints(res: Response, json: object): void {
58 return send_message_on_status(res, 103, json);
62 * Sends a "110 Response is Stale" response.
63 * @param res - The Express response object.
64 * @param json - The JSON object to send.
66 export function response_is_stale(res: Response, json: object): void {
67 return send_message_on_status(res, 110, json);
72 * Sends a "200 Success" response.
73 * @param res - The Express response object.
74 * @param json - The JSON object to send.
76 export function success(res: Response, json: object): void {
77 return send_message_on_status(res, 200, json);
81 * Sends a "201 Created" response.
82 * @param res - The Express response object.
83 * @param json - The JSON object to send.
85 export function created(res: Response, json: object): void {
86 return send_message_on_status(res, 201, json);
90 * Sends a "202 Accepted" response.
91 * @param res - The Express response object.
92 * @param json - The JSON object to send.
94 export function accepted(res: Response, json: object): void {
95 return send_message_on_status(res, 202, json);
99 * Sends a "203 Non Authoritative Information" response.
100 * @param res - The Express response object.
101 * @param json - The JSON object to send.
103 export function non_authoritative_information(res: Response, json: object): void {
104 return send_message_on_status(res, 203, json);
108 * Sends a "204 No Content" response.
109 * @param res - The Express response object.
110 * @param json - The JSON object to send.
112 export function no_content(res: Response, json: object): void {
113 return send_message_on_status(res, 204, json);
117 * Sends a "205 Reset Content" response.
118 * @param res - The Express response object.
119 * @param json - The JSON object to send.
121 export function reset_content(res: Response, json: object): void {
122 return send_message_on_status(res, 205, json);
126 * Sends a "206 Partial Content" response.
127 * @param res - The Express response object.
128 * @param json - The JSON object to send.
130 export function partial_content(res: Response, json: object): void {
131 return send_message_on_status(res, 206, json);
135 * Sends a "207 Multi Status" response.
136 * @param res - The Express response object.
137 * @param json - The JSON object to send.
139 export function multi_status(res: Response, json: object): void {
140 return send_message_on_status(res, 207, json);
144 * Sends a "208 Already Reported" response.
145 * @param res - The Express response object.
146 * @param json - The JSON object to send.
148 export function already_reported(res: Response, json: object): void {
149 return send_message_on_status(res, 208, json);
153 * Sends a "226 Im Used" response.
154 * @param res - The Express response object.
155 * @param json - The JSON object to send.
157 export function im_used(res: Response, json: object): void {
158 return send_message_on_status(res, 226, json);
164 * Sends a "300 Multiple Choices" response.
165 * @param res - The Express response object.
166 * @param json - The JSON object to send.
168 export function multiple_choices(res: Response, json: object): void {
169 return send_message_on_status(res, 300, json);
173 * Sends a "301 Moved Permanently" response.
174 * @param res - The Express response object.
175 * @param json - The JSON object to send.
177 export function moved_permanently(res: Response, json: object): void {
178 return send_message_on_status(res, 301, json);
182 * Sends a "302 Found" response.
183 * @param res - The Express response object.
184 * @param json - The JSON object to send.
186 export function found(res: Response, json: object): void {
187 return send_message_on_status(res, 302, json);
191 * Sends a "303 See Other" response.
192 * @param res - The Express response object.
193 * @param json - The JSON object to send.
195 export function see_other(res: Response, json: object): void {
196 return send_message_on_status(res, 303, json);
200 * Sends a "304 Not Modified" response.
201 * @param res - The Express response object.
202 * @param json - The JSON object to send.
204 export function not_modified(res: Response, json: object): void {
205 return send_message_on_status(res, 304, json);
209 * Sends a "305 Use Proxy" response.
210 * @param res - The Express response object.
211 * @param json - The JSON object to send.
213 export function use_proxy(res: Response, json: object): void {
214 return send_message_on_status(res, 305, json);
218 * Sends a "306 Switch Proxy" response.
219 * @param res - The Express response object.
220 * @param json - The JSON object to send.
222 export function switch_proxy(res: Response, json: object): void {
223 return send_message_on_status(res, 306, json);
227 * Sends a "307 Temporary Redirect" response.
228 * @param res - The Express response object.
229 * @param json - The JSON object to send.
231 export function temporary_redirect(res: Response, json: object): void {
232 return send_message_on_status(res, 307, json);
236 * Sends a "308 Permanent Redirect" response.
237 * @param res - The Express response object.
238 * @param json - The JSON object to send.
240 export function permanent_redirect(res: Response, json: object): void {
241 return send_message_on_status(res, 308, json);
247 * Sends a "400 Bad Request" response.
248 * @param res - The Express response object.
249 * @param json - The JSON object to send.
251 export function bad_request(res: Response, json: object): void {
252 return send_message_on_status(res, 400, json);
256 * Sends a "401 Unauthorized" response.
257 * @param res - The Express response object.
258 * @param json - The JSON object to send.
260 export function unauthorized(res: Response, json: object): void {
261 return send_message_on_status(res, 401, json);
265 * Sends a "402 Payment Required" response.
266 * @param res - The Express response object.
267 * @param json - The JSON object to send.
269 export function payment_required(res: Response, json: object): void {
270 return send_message_on_status(res, 402, json);
274 * Sends a "403 Forbidden" response.
275 * @param res - The Express response object.
276 * @param json - The JSON object to send.
278 export function forbidden(res: Response, json: object): void {
279 return send_message_on_status(res, 403, json);
283 * Sends a "404 Not Found" response.
284 * @param res - The Express response object.
285 * @param json - The JSON object to send.
287 export function not_found(res: Response, json: object): void {
288 return send_message_on_status(res, 404, json);
292 * Sends a "405 Method Not Allowed" response.
293 * @param res - The Express response object.
294 * @param json - The JSON object to send.
296 export function method_not_allowed(res: Response, json: object): void {
297 return send_message_on_status(res, 405, json);
301 * Sends a "406 Not Acceptable" response.
302 * @param res - The Express response object.
303 * @param json - The JSON object to send.
305 export function not_acceptable(res: Response, json: object): void {
306 return send_message_on_status(res, 406, json);
310 * Sends a "407 Proxy Authentication Required" response.
311 * @param res - The Express response object.
312 * @param json - The JSON object to send.
314 export function proxy_authentication_required(res: Response, json: object): void {
315 return send_message_on_status(res, 407, json);
319 * Sends a "408 Request Timeout" response.
320 * @param res - The Express response object.
321 * @param json - The JSON object to send.
323 export function request_timeout(res: Response, json: object): void {
324 return send_message_on_status(res, 408, json);
328 * Sends a "409 Conflict" response.
329 * @param res - The Express response object.
330 * @param json - The JSON object to send.
332 export function conflict(res: Response, json: object): void {
333 return send_message_on_status(res, 409, json);
337 * Sends a "410 Gone" response.
338 * @param res - The Express response object.
339 * @param json - The JSON object to send.
341 export function gone(res: Response, json: object): void {
342 return send_message_on_status(res, 410, json);
346 * Sends a "411 Length Required" response.
347 * @param res - The Express response object.
348 * @param json - The JSON object to send.
350 export function length_required(res: Response, json: object): void {
351 return send_message_on_status(res, 411, json);
355 * Sends a "412 Precondition Failed" response.
356 * @param res - The Express response object.
357 * @param json - The JSON object to send.
359 export function precondition_failed(res: Response, json: object): void {
360 return send_message_on_status(res, 412, json);
364 * Sends a "413 Payload Too Large" response.
365 * @param res - The Express response object.
366 * @param json - The JSON object to send.
368 export function payload_too_large(res: Response, json: object): void {
369 return send_message_on_status(res, 413, json);
373 * Sends a "414 Uri Too Long" response.
374 * @param res - The Express response object.
375 * @param json - The JSON object to send.
377 export function uri_too_long(res: Response, json: object): void {
378 return send_message_on_status(res, 414, json);
382 * Sends a "415 Unsupported Media Type" response.
383 * @param res - The Express response object.
384 * @param json - The JSON object to send.
386 export function unsupported_media_type(res: Response, json: object): void {
387 return send_message_on_status(res, 415, json);
391 * Sends a "416 Range Not Satisfiable" response.
392 * @param res - The Express response object.
393 * @param json - The JSON object to send.
395 export function range_not_satisfiable(res: Response, json: object): void {
396 return send_message_on_status(res, 416, json);
400 * Sends a "417 Expectation Failed" response.
401 * @param res - The Express response object.
402 * @param json - The JSON object to send.
404 export function expectation_failed(res: Response, json: object): void {
405 return send_message_on_status(res, 417, json);
409 * Sends a "418 Im A Teapot" response.
410 * @param res - The Express response object.
411 * @param json - The JSON object to send.
413 export function im_a_teapot(res: Response, json: object): void {
414 return send_message_on_status(res, 418, json);
418 * Sends a "421 Misdirected Request" response.
419 * @param res - The Express response object.
420 * @param json - The JSON object to send.
422 export function misdirected_request(res: Response, json: object): void {
423 return send_message_on_status(res, 421, json);
427 * Sends a "422 Unprocessable Entity" response.
428 * @param res - The Express response object.
429 * @param json - The JSON object to send.
431 export function unprocessable_entity(res: Response, json: object): void {
432 return send_message_on_status(res, 422, json);
436 * Sends a "423 locked" response.
437 * @param res - The Express response object.
438 * @param json - The JSON object to send.
440 export function locked(res: Response, json: object): void {
441 return send_message_on_status(res, 423, json);
445 * Sends a "424 Failed Dependency" response.
446 * @param res - The Express response object.
447 * @param json - The JSON object to send.
449 export function failed_dependency(res: Response, json: object): void {
450 return send_message_on_status(res, 424, json);
454 * Sends a "425 Too Early" response.
455 * @param res - The Express response object.
456 * @param json - The JSON object to send.
458 export function too_early(res: Response, json: object): void {
459 return send_message_on_status(res, 425, json);
463 * Sends a "426 Upgrade Required" response.
464 * @param res - The Express response object.
465 * @param json - The JSON object to send.
467 export function upgrade_required(res: Response, json: object): void {
468 return send_message_on_status(res, 426, json);
472 * Sends a "428 Precondition Required" response.
473 * @param res - The Express response object.
474 * @param json - The JSON object to send.
476 export function precondition_required(res: Response, json: object): void {
477 return send_message_on_status(res, 428, json);
481 * Sends a "429 Too Many Requests" response.
482 * @param res - The Express response object.
483 * @param json - The JSON object to send.
485 export function too_many_requests(res: Response, json: object): void {
486 return send_message_on_status(res, 429, json);
490 * Sends a "431 Request Header Fields Too Large" response.
491 * @param res - The Express response object.
492 * @param json - The JSON object to send.
494 export function request_header_fields_too_large(res: Response, json: object): void {
495 return send_message_on_status(res, 431, json);
499 * Sends a "451 Unavailable For Legal Reasons" response.
500 * @param res - The Express response object.
501 * @param json - The JSON object to send.
503 export function unavailable_for_legal_reasons(res: Response, json: object): void {
504 return send_message_on_status(res, 451, json);
508 * Sends a "498 Invalid Token" response.
509 * @param res - The Express response object.
510 * @param json - The JSON object to send.
512 export function invalid_token(res: Response, json: object): void {
513 return send_message_on_status(res, 498, json);
519 * Sends a "500 Internal Server Error" response.
520 * @param res - The Express response object.
521 * @param json - The JSON object to send.
523 export function internal_server_error(res: Response, json: object): void {
524 return send_message_on_status(res, 500, json);
528 * Sends a "501 Not Implemented" response.
529 * @param res - The Express response object.
530 * @param json - The JSON object to send.
532 export function not_implemented(res: Response, json: object): void {
533 return send_message_on_status(res, 501, json);
537 * Sends a "502 Bad Gateway" response.
538 * @param res - The Express response object.
539 * @param json - The JSON object to send.
541 export function bad_gateway(res: Response, json: object): void {
542 return send_message_on_status(res, 502, json);
546 * Sends a "503 Service Unavailable" response.
547 * @param res - The Express response object.
548 * @param json - The JSON object to send.
550 export function service_unavailable(res: Response, json: object): void {
551 return send_message_on_status(res, 503, json);
555 * Sends a "504 Gateway Timeout" response.
556 * @param res - The Express response object.
557 * @param json - The JSON object to send.
559 export function gateway_timeout(res: Response, json: object): void {
560 return send_message_on_status(res, 504, json);
564 * Sends a "505 Http Version Not Supported" response.
565 * @param res - The Express response object.
566 * @param json - The JSON object to send.
568 export function http_version_not_supported(res: Response, json: object): void {
569 return send_message_on_status(res, 505, json);
573 * Sends a "506 Variant Also Negotiates" response.
574 * @param res - The Express response object.
575 * @param json - The JSON object to send.
577 export function variant_also_negotiates(res: Response, json: object): void {
578 return send_message_on_status(res, 506, json);
582 * Sends a "507 Insufficient Storage" response.
583 * @param res - The Express response object.
584 * @param json - The JSON object to send.
586 export function insufficient_storage(res: Response, json: object): void {
587 return send_message_on_status(res, 507, json);
591 * Sends a "508 Loop Detected" response.
592 * @param res - The Express response object.
593 * @param json - The JSON object to send.
595 export function loop_detected(res: Response, json: object): void {
596 return send_message_on_status(res, 508, json);
600 * Sends a "510 Not Extended" response.
601 * @param res - The Express response object.
602 * @param json - The JSON object to send.
604 export function not_extended(res: Response, json: object): void {
605 return send_message_on_status(res, 510, json);
609 * Sends a "511 Network Authentication Required" response.
610 * @param res - The Express response object.
611 * @param json - The JSON object to send.
613 export function network_authentication_required(res: Response, json: object): void {
614 return send_message_on_status(res, 511, json);