# hadid-http-status
HTTP status constants, reason phrases, category predicates, and JSON API envelope helpers for Hadid Web APIs.
## Installation
```sh
hadid add hadid-http-status
```
## Usage
```hadid
import "hadid-http-status" as http;
print(http.status_text(201)); // -> Created
assert(http.is_success(200), "2xx");
print(http.api_ok("{\"hello\":\"world\"}"));
```
Alle HADID-Pakete
hadid-http-status
v0.1.0BLAKE2b-256HTTP status code constants, category predicates, and JSON API envelopes for Hadid
# hadid-http-status
HTTP status constants, reason phrases, category predicates, and JSON API envelope helpers for Hadid Web APIs.
## Installation
```sh
hadid add hadid-http-status
```
## Usage
```hadid
import "hadid-http-status" as http;
print(http.status_text(201)); // -> Created
assert(http.is_success(200), "2xx");
print(http.api_ok("{\"hello\":\"world\"}"));
```
[package]
name = "hadid-http-status"
version = "0.1.0"
entry = "src/lib.had"
description = "HTTP status code constants, category predicates, and JSON API envelopes for Hadid"
license = "MIT"
keywords = "http,status,web,api,rest"
repository = "https://github.com/DGTLHLHAT/hadid"
[dependencies]
// hadid-http-status: HTTP status helpers and JSON API response envelopes
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_NO_CONTENT = 204;
const HTTP_BAD_REQUEST = 400;
const HTTP_UNAUTHORIZED = 401;
const HTTP_FORBIDDEN = 403;
const HTTP_NOT_FOUND = 404;
const HTTP_CONFLICT = 409;
const HTTP_TOO_MANY_REQUESTS = 429;
const HTTP_INTERNAL_ERROR = 500;
const HTTP_SERVICE_UNAVAILABLE = 503;
fn is_success(code: i32): bool {
if (code >= 200) {
if (code < 300) { return true; }
}
return false;
}
fn is_redirect(code: i32): bool {
if (code >= 300) {
if (code < 400) { return true; }
}
return false;
}
fn is_client_error(code: i32): bool {
if (code >= 400) {
if (code < 500) { return true; }
}
return false;
}
fn is_server_error(code: i32): bool {
if (code >= 500) {
if (code < 600) { return true; }
}
return false;
}
fn status_text(code: i32): string {
if (code == 200) { return "OK"; }
if (code == 201) { return "Created"; }
if (code == 204) { return "No Content"; }
if (code == 400) { return "Bad Request"; }
if (code == 401) { return "Unauthorized"; }
if (code == 403) { return "Forbidden"; }
if (code == 404) { return "Not Found"; }
if (code == 409) { return "Conflict"; }
if (code == 429) { return "Too Many Requests"; }
if (code == 500) { return "Internal Server Error"; }
if (code == 503) { return "Service Unavailable"; }
return "Unknown";
}
fn api_ok(data_json: string): string {
return "{\"ok\":true,\"data\":" + data_json + "}";
}
fn api_err(code: string, message: string): string {
let qc = "\"error\"";
let qm = "\"\"";
match (json_quote(code)) { Ok(v) => { qc = v; } Err(e) => {} }
match (json_quote(message)) { Ok(v) => { qm = v; } Err(e) => {} }
return "{\"ok\":false,\"error\":{\"code\":" + qc + ",\"message\":" + qm + "}}";
}
| Version | Größe | Downloads | BLAKE2b-256 | Status |
|---|---|---|---|---|
| v0.1.0 | 3050 B | 0 | blake2b-256:335408081c10… | Aktiv |