package polymarket
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=4eb4c5d2f63ff081c9713d90be5a51b2
sha512=0e3de0c9b40683e09ab8f9f966a44784ef1b9b482c3eefef84104a7e8042c92f1d79893ee9588b24fa3d0decaed7f365509f4d1c23c66ce8328efb64e721f276
doc/polymarket.http/Polymarket_http/Builder/index.html
Module Polymarket_http.BuilderSource
Type-safe request builder with phantom types.
This module provides a builder pattern for HTTP requests with compile-time enforcement of:
- POST requires a body before execution
- GET/DELETE are ready to execute immediately
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).
Request Constructors
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.
Query Parameter Builders
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
Header Builders
Auth
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.
Body
Add a request body. Changes state from not_ready to ready.
Execution
Execute the request and return raw (status, body). Use this for custom response handling.
Response Parsers
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.