Polymarket_http.BuilderSourceType-safe request builder with phantom types.
This module provides a builder pattern for HTTP requests with compile-time enforcement of:
Example usage:
(* GET request - returns parsed JSON list *)
new_get client "/positions"
|> query_param "user" user
|> query_option "limit" string_of_int limit
|> fetch_json_list position_of_yojson
(* POST with body *)
new_post client "/order"
|> header_list auth_headers
|> with_body body
|> fetch_json order_of_yojson
(* Raw execution for custom handling *)
new_get client "/health"
|> fetch
|> fun (status, body) -> ...Phantom type indicating request is ready to execute
Phantom type indicating request needs a body before execution
Request builder type. 'state tracks whether request is ready to execute (either ready or not_ready).
Create a GET request. Ready to execute immediately.
Create a POST request. Requires with_body before execution.
Create a DELETE request. Ready to execute immediately.
Create a DELETE request with body. Requires with_body before execution. Used for APIs that require a JSON body in DELETE requests.
Add an optional parameter with a converter function.
Add an optional list parameter, joining values with commas.
Add an optional boolean parameter (renders as "true"/"false").
Add each value as a separate query parameter with the same key. query_each "id" string_of_int (Some [1; 2]) produces ?id=1&id=2
val with_l1_auth :
private_key:Polymarket_common.Crypto.private_key ->
address:string ->
nonce:int ->
'a t ->
'a tAdd L1 authentication headers for wallet-based endpoints.
val with_l2_auth :
credentials:Polymarket_common.Auth.credentials ->
address:string ->
'a t ->
'a tAdd L2 authentication headers. Computes headers from the request's method, path, and body. Must be called after with_body for POST requests.
Add a request body. Changes state from not_ready to ready.
Execute the request and return raw (status, body). Use this for custom response handling.
These execute the request and parse the response in one step.
Pass ~expected_fields (from @@deriving yojson_fields) to log warnings when the API returns fields not in our types.
val fetch_json :
?expected_fields:string list ->
?context:string ->
(Yojson.Safe.t -> 'a) ->
ready t ->
('a, Client.error) resultExecute and parse response as JSON object.
val fetch_json_list :
?expected_fields:string list ->
?context:string ->
(Yojson.Safe.t -> 'a) ->
ready t ->
('a list, Client.error) resultExecute and parse response as JSON array.
Execute and return response body as string.
Execute and discard response body. Succeeds on 200/201/204.