Hcs.Method
hcs · API reference
HCS HTTP method type and conversion helpers.
HCS exposes compact polymorphic variants such as GET`, POST, ``HEAD, and ``Other "PATCH"`. Use this module to convert to/from strings or the underlying HTTP codec representation.
HTTP request methods used by HCS handlers, routers, plugs, and clients.
The public method type is a polymorphic variant so application code can pattern-match directly:
match Hcs.Request.meth req with
| `GET -> Hcs.Response.text "read"
| `POST -> Hcs.Response.text "write"
| `Other m -> Hcs.Response.text ("custom method: " ^ m)
| _ -> Hcs.Response.method_not_allowed ~allowed:[ `GET; `POST ] ()Standard methods are represented by constructors. Non-standard methods use Other name`. `PATCH` is represented as Other "PATCH"` for compatibility with older HCS APIs.
type t = [
| `GET
| `HEAD
| `POST
| `PUT
| `DELETE
| `CONNECT
| `OPTIONS
| `TRACE
| `Other of string
]Public HTTP method type.
val to_string : t -> stringConvert a method to the wire spelling, e.g. ``GETto"GET"`.
val of_string : string -> tParse a method string. Unknown methods become ``Other s`.
val to_core : t -> Http_core.Method.tConvert to the underlying http codec method type. Intended for protocol boundary code; application handlers rarely need it.
val of_core : Http_core.Method.t -> tConvert from the underlying http codec method type.
val is_safe : t -> booltrue for methods considered safe by HTTP semantics.
val is_idempotent : t -> booltrue for methods considered idempotent by HTTP semantics.