Hcs.Request
hcs · API reference
Lazy request accessors.
Server.request stores the method, target, version, headers, assigns, and body reader. Use this module to read headers, query parameters, form fields, the path, the body, and typed request metadata. Header and body work is lazy, so handlers pay only for the parts they inspect.
Lazy request accessors.
HCS parses the request method, target, and protocol version eagerly. Headers, query parameters, form fields, and bodies are accessed through this module so handlers pay only for what they inspect.
Example:
let handler req =
match Hcs.Request.query req "page" with
| Some page -> Hcs.Response.text page
| None -> Hcs.Response.bad_request ()type t = Server.requestAlias for the server request type.
val meth : t -> Method.tval target : t -> stringval version : t -> Server.protocol_versionval assigns : t -> Assigns.tEager request metadata.
val with_assign : t -> 'a Assigns.key -> 'a -> twith_assign req key value returns req with value attached under key in its assigns. A plug uses this to hand typed per-request data (the current account, a parsed body, …) to downstream handlers, which read it back with assign.
val with_assigns : t -> Assigns.t -> twith_assigns req a replaces the request's assigns wholesale.
val assign : t -> 'a Assigns.key -> 'a optionassign req key is the value attached under key, if any — the counterpart to with_assign.
val header : t -> string -> string optionval header_multi : t -> string -> string listval headers : t -> (string * string) listval has_header : t -> string -> boolval set_header : t -> string -> string -> tval content_type : t -> string optionval content_length : t -> int64 optionval host : t -> string optionval accept : t -> string optionval authorization : t -> string optionval is_keep_alive : t -> boolval accepts_json : t -> boolval accepts_html : t -> boolHeader helpers. Header lookup is case-insensitive.
val path : t -> stringval query_string : t -> string optionval parse_query_string : string -> (string * string) listval query_params : t -> (string * string) listval query : t -> string -> string optionval query_or : default:string -> t -> string -> stringval query_all : t -> string -> string listval query_int : t -> string -> int optionval query_int_or : default:int -> t -> string -> intval query_bool : t -> string -> bool optionval query_bool_or : default:bool -> t -> string -> boolval query_float : t -> string -> float optionval query_float_or : default:float -> t -> string -> floatTarget and query-string helpers.
val is_get : t -> boolval is_post : t -> boolval is_put : t -> boolval is_delete : t -> boolval is_patch : t -> boolval is_head : t -> boolval is_options : t -> boolval is_safe : t -> boolval is_idempotent : t -> boolMethod predicates.
val body : t -> stringval body_stream : t -> unit -> Cstruct.t optionval close_body : t -> unitval with_body : t -> string -> tval body_string : t -> stringval body_length : t -> intval has_body : t -> boolBody helpers. body materializes the body; body_stream consumes chunks.
val form_decode : string -> stringval parse_form_body : string -> (string * string) listval form_data : t -> (string * string) listval form_data_from_body : string -> (string * string) listval form_field : t -> string -> string optionval form_field_or : default:string -> t -> string -> stringval form_int : t -> string -> int optionval form_int_or : default:int -> t -> string -> intapplication/x-www-form-urlencoded helpers.