@@ -5,6 +5,7 @@ module Yoga.HTTP.API.Route.StatusCode
55 , statusCodeFor
66 , statusCodeToString
77 , StatusCode(..)
8+ , class StatusCodeToLabel
89 ) where
910
1011import Prelude
@@ -264,3 +265,39 @@ instance StatusCodeMapImpl (Proxy sym) => StatusCodeMap sym where
264265-- | Convert StatusCode to String for OpenAPI generation
265266statusCodeToString :: StatusCode -> String
266267statusCodeToString (StatusCode n) = show n
268+
269+--------------------------------------------------------------------------------
270+-- Status Code to Label Mapping
271+--------------------------------------------------------------------------------
272+
273+-- | Map numeric status codes to their label names
274+class StatusCodeToLabel (code :: Int) (label :: Symbol) | code -> label
275+
276+-- 2xx Success
277+instance StatusCodeToLabel 200 "ok"
278+instance StatusCodeToLabel 201 "created"
279+instance StatusCodeToLabel 202 "accepted"
280+instance StatusCodeToLabel 204 "noContent"
281+
282+-- 3xx Redirection
283+instance StatusCodeToLabel 301 "movedPermanently"
284+instance StatusCodeToLabel 302 "found"
285+instance StatusCodeToLabel 303 "seeOther"
286+instance StatusCodeToLabel 304 "notModified"
287+instance StatusCodeToLabel 307 "temporaryRedirect"
288+instance StatusCodeToLabel 308 "permanentRedirect"
289+
290+-- 4xx Client Errors
291+instance StatusCodeToLabel 400 "badRequest"
292+instance StatusCodeToLabel 401 "unauthorized"
293+instance StatusCodeToLabel 403 "forbidden"
294+instance StatusCodeToLabel 404 "notFound"
295+instance StatusCodeToLabel 409 "conflict"
296+instance StatusCodeToLabel 422 "unprocessableEntity"
297+instance StatusCodeToLabel 429 "tooManyRequests"
298+
299+-- 5xx Server Errors
300+instance StatusCodeToLabel 500 "internalServerError"
301+instance StatusCodeToLabel 502 "badGateway"
302+instance StatusCodeToLabel 503 "serviceUnavailable"
303+