Module Method

HTTP request methods per RFC 9110 Section 9

HTTP methods indicate the desired action to be performed on a resource. The method token is case-sensitive.

Safe Methods

Methods are considered "safe" if their semantics are read-only (GET, HEAD, OPTIONS, TRACE). Per RFC 9110 Section 9.2.1.

Idempotent Methods

A method is "idempotent" if multiple identical requests have the same effect as a single request (GET, HEAD, PUT, DELETE, OPTIONS, TRACE). Per RFC 9110 Section 9.2.2.

val src : Logs.Src.t

Log source for method operations

type t = [
  1. | `GET
    (*

    Retrieve a resource

    *)
  2. | `POST
    (*

    Submit data to be processed

    *)
  3. | `PUT
    (*

    Replace a resource

    *)
  4. | `DELETE
    (*

    Delete a resource

    *)
  5. | `HEAD
    (*

    Retrieve headers only

    *)
  6. | `OPTIONS
    (*

    Retrieve allowed methods

    *)
  7. | `PATCH
    (*

    Partial resource modification

    *)
  8. | `CONNECT
    (*

    Establish tunnel to server

    *)
  9. | `TRACE
    (*

    Echo received request

    *)
  10. | `Other of string
    (*

    Non-standard or extension method

    *)
]

HTTP method type using polymorphic variants for better composability

Conversion Functions

val to_string : t -> string

Convert method to uppercase string representation

val of_string : string -> t

Parse method from string (case-insensitive). Returns `Other s for unrecognized methods.

val pp : Format.formatter -> t -> unit

Pretty printer for methods

Method Properties

val is_safe : t -> bool

Returns true for safe methods (GET, HEAD, OPTIONS, TRACE). Safe methods should not have side effects.

val is_idempotent : t -> bool

Returns true for idempotent methods (GET, HEAD, PUT, DELETE, OPTIONS, TRACE). Idempotent methods can be called multiple times with the same result.

type body_semantics =
  1. | Body_required
    (*

    Method requires a body (POST, PUT, PATCH)

    *)
  2. | Body_optional
    (*

    Method MAY have a body (DELETE, OPTIONS, GET)

    *)
  3. | Body_forbidden
    (*

    Method MUST NOT have a body (HEAD, TRACE, CONNECT)

    *)

Request body semantics per RFC 9110 Section 9.3

val request_body_semantics : t -> body_semantics

Returns the request body semantics for a method per RFC 9110.

val has_request_body : t -> bool

Returns true for methods that typically have a request body (POST, PUT, PATCH).

val is_cacheable : t -> bool

Returns true for methods whose responses are cacheable by default (GET, HEAD, POST). Note: POST is only cacheable with explicit cache headers.

Comparison

val equal : t -> t -> bool

Compare two methods for equality

val compare : t -> t -> int

Compare two methods for ordering