{"name":"hadid-http-status","version":"0.1.0","description":"HTTP status code constants, category predicates, and JSON API envelopes for Hadid","license":"MIT","files":[{"path":"README.md","content":"# hadid-http-status\n\nHTTP status constants, reason phrases, category predicates, and JSON API envelope helpers for Hadid Web APIs.\n\n## Installation\n\n```sh\nhadid add hadid-http-status\n```\n\n## Usage\n\n```hadid\nimport \"hadid-http-status\" as http;\n\nprint(http.status_text(201)); // -> Created\nassert(http.is_success(200), \"2xx\");\nprint(http.api_ok(\"{\\\"hello\\\":\\\"world\\\"}\"));\n```\n"},{"path":"hadid.toml","content":"[package]\nname = \"hadid-http-status\"\nversion = \"0.1.0\"\nentry = \"src/lib.had\"\ndescription = \"HTTP status code constants, category predicates, and JSON API envelopes for Hadid\"\nlicense = \"MIT\"\nkeywords = \"http,status,web,api,rest\"\nrepository = \"https://github.com/DGTLHLHAT/hadid\"\n\n[dependencies]\n"},{"path":"src/lib.had","content":"// hadid-http-status: HTTP status helpers and JSON API response envelopes\n\nconst HTTP_OK = 200;\nconst HTTP_CREATED = 201;\nconst HTTP_NO_CONTENT = 204;\nconst HTTP_BAD_REQUEST = 400;\nconst HTTP_UNAUTHORIZED = 401;\nconst HTTP_FORBIDDEN = 403;\nconst HTTP_NOT_FOUND = 404;\nconst HTTP_CONFLICT = 409;\nconst HTTP_TOO_MANY_REQUESTS = 429;\nconst HTTP_INTERNAL_ERROR = 500;\nconst HTTP_SERVICE_UNAVAILABLE = 503;\n\nfn is_success(code: i32): bool {\n    if (code >= 200) {\n        if (code < 300) { return true; }\n    }\n    return false;\n}\n\nfn is_redirect(code: i32): bool {\n    if (code >= 300) {\n        if (code < 400) { return true; }\n    }\n    return false;\n}\n\nfn is_client_error(code: i32): bool {\n    if (code >= 400) {\n        if (code < 500) { return true; }\n    }\n    return false;\n}\n\nfn is_server_error(code: i32): bool {\n    if (code >= 500) {\n        if (code < 600) { return true; }\n    }\n    return false;\n}\n\nfn status_text(code: i32): string {\n    if (code == 200) { return \"OK\"; }\n    if (code == 201) { return \"Created\"; }\n    if (code == 204) { return \"No Content\"; }\n    if (code == 400) { return \"Bad Request\"; }\n    if (code == 401) { return \"Unauthorized\"; }\n    if (code == 403) { return \"Forbidden\"; }\n    if (code == 404) { return \"Not Found\"; }\n    if (code == 409) { return \"Conflict\"; }\n    if (code == 429) { return \"Too Many Requests\"; }\n    if (code == 500) { return \"Internal Server Error\"; }\n    if (code == 503) { return \"Service Unavailable\"; }\n    return \"Unknown\";\n}\n\nfn api_ok(data_json: string): string {\n    return \"{\\\"ok\\\":true,\\\"data\\\":\" + data_json + \"}\";\n}\n\nfn api_err(code: string, message: string): string {\n    let qc = \"\\\"error\\\"\";\n    let qm = \"\\\"\\\"\";\n    match (json_quote(code)) { Ok(v) => { qc = v; } Err(e) => {} }\n    match (json_quote(message)) { Ok(v) => { qm = v; } Err(e) => {} }\n    return \"{\\\"ok\\\":false,\\\"error\\\":{\\\"code\\\":\" + qc + \",\\\"message\\\":\" + qm + \"}}\";\n}\n"}]}