Hcs.Status

hcs · API reference

HCS HTTP status type and conversion helpers.

Use this module to convert status variants to numeric codes and reason phrases, or to map integer codes back to HCS status values.

HTTP response status codes used by HCS responses and clients.

The public status type is a polymorphic variant for ergonomic construction and matching:

  let response = Hcs.Response.make ~status:`Created "ok"

  match response.Hcs.Response.status with
  | `OK | `Created -> ...
  | `Code n when n >= 500 -> ...
  | _ -> ...

Use ``Code n` for extension status codes that do not have a named constructor.

type t = [ 
  | `Continue
  | `Switching_protocols
  | `OK
  | `Created
  | `Accepted
  | `Non_authoritative_information
  | `No_content
  | `Reset_content
  | `Partial_content
  | `Multiple_choices
  | `Moved_permanently
  | `Found
  | `See_other
  | `Not_modified
  | `Use_proxy
  | `Temporary_redirect
  | `Bad_request
  | `Unauthorized
  | `Payment_required
  | `Forbidden
  | `Not_found
  | `Method_not_allowed
  | `Not_acceptable
  | `Proxy_authentication_required
  | `Request_timeout
  | `Conflict
  | `Gone
  | `Length_required
  | `Precondition_failed
  | `Payload_too_large
  | `Uri_too_long
  | `Unsupported_media_type
  | `Range_not_satisfiable
  | `Expectation_failed
  | `I_m_a_teapot
  | `Enhance_your_calm
  | `Upgrade_required
  | `Precondition_required
  | `Too_many_requests
  | `Request_header_fields_too_large
  | `Internal_server_error
  | `Not_implemented
  | `Bad_gateway
  | `Service_unavailable
  | `Gateway_timeout
  | `Http_version_not_supported
  | `Network_authentication_required
  | `Code of int
 ]

Public HTTP status type.

val to_code : t -> int

Numeric HTTP status code.

val of_code : int -> t

Convert a numeric status code to a named constructor when known, or ``Code n` otherwise.

val to_int : t -> int

Alias of to_code.

val reason_phrase : t -> string

Standard reason phrase for the status code.

val to_core : t -> Http_core.Status.t

Convert to the underlying http codec status type. Intended for protocol boundary code.

val of_core : Http_core.Status.t -> t

Convert from the underlying http codec status type.