this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+20 -49
+2 -1
stack/requests/lib/response.ml
··· 60 60 (* Consume remaining body if any *) 61 61 try 62 62 (* Read and discard remaining data by copying to a buffer *) 63 + (* TODO make this a more efficient null sink *) 63 64 let buf = Buffer.create 4096 in 64 65 Eio.Flow.copy t.body (Eio.Flow.buffer_sink buf) 65 66 with _ -> (); ··· 89 90 elapsed: %.3fs@,\ 90 91 @[%a@]@]" 91 92 t.status status_desc t.url t.elapsed 92 - Headers.pp t.headers 93 + Headers.pp t.headers
+3 -40
stack/requests/lib/session.ml
··· 250 250 in 251 251 execute_request t ?headers ?auth ?timeout ~method_:`GET url 252 252 253 - let post t ?headers ?body ?auth ?timeout ?json ?form url = 254 - let body, headers = match json, form, body with 255 - | Some json, _, _ -> 256 - let json_str = Yojson.Safe.to_string json in 257 - let body = Body.json json_str in 258 - let headers = Option.value headers ~default:Headers.empty 259 - |> Headers.content_type Mime.json in 260 - Some body, Some headers 261 - | _, Some form, _ -> 262 - let form_str = 263 - form 264 - |> List.map (fun (k, v) -> Uri.pct_encode k ^ "=" ^ Uri.pct_encode v) 265 - |> String.concat "&" 266 - in 267 - let body = Body.text form_str in 268 - let headers = Option.value headers ~default:Headers.empty 269 - |> Headers.content_type Mime.form in 270 - Some body, Some headers 271 - | _, _, body -> body, headers 272 - in 253 + let post t ?headers ?body ?auth ?timeout url = 273 254 execute_request t ?headers ?body ?auth ?timeout ~method_:`POST url 274 255 275 - let put t ?headers ?body ?auth ?timeout ?json url = 276 - let body, headers = match json with 277 - | Some json -> 278 - let json_str = Yojson.Safe.to_string json in 279 - let body = Body.json json_str in 280 - let headers = Option.value headers ~default:Headers.empty 281 - |> Headers.content_type Mime.json in 282 - Some body, Some headers 283 - | None -> body, headers 284 - in 256 + let put t ?headers ?body ?auth ?timeout url = 285 257 execute_request t ?headers ?body ?auth ?timeout ~method_:`PUT url 286 258 287 - let patch t ?headers ?body ?auth ?timeout ?json url = 288 - let body, headers = match json with 289 - | Some json -> 290 - let json_str = Yojson.Safe.to_string json in 291 - let body = Body.json json_str in 292 - let headers = Option.value headers ~default:Headers.empty 293 - |> Headers.content_type Mime.json in 294 - Some body, Some headers 295 - | None -> body, headers 296 - in 259 + let patch t ?headers ?body ?auth ?timeout url = 297 260 execute_request t ?headers ?body ?auth ?timeout ~method_:`PATCH url 298 261 299 262 let delete t ?headers ?auth ?timeout url =
+15 -8
stack/requests/lib/session.mli
··· 159 159 ?body:Body.t -> 160 160 ?auth:Auth.t -> 161 161 ?timeout:Timeout.t -> 162 - ?json:Yojson.Safe.t -> 163 - ?form:(string * string) list -> 164 162 string -> 165 163 Response.t 166 - (** POST request with optional JSON or form data *) 164 + (** POST request with optional body *) 167 165 168 166 val put : 169 167 (_ Eio.Time.clock, _ Eio.Net.t) t -> ··· 171 169 ?body:Body.t -> 172 170 ?auth:Auth.t -> 173 171 ?timeout:Timeout.t -> 174 - ?json:Yojson.Safe.t -> 175 172 string -> 176 173 Response.t 177 - (** PUT request with optional JSON data *) 174 + (** PUT request with optional body *) 178 175 179 176 val patch : 180 177 (_ Eio.Time.clock, _ Eio.Net.t) t -> ··· 182 179 ?body:Body.t -> 183 180 ?auth:Auth.t -> 184 181 ?timeout:Timeout.t -> 185 - ?json:Yojson.Safe.t -> 186 182 string -> 187 183 Response.t 188 - (** PATCH request with optional JSON data *) 184 + (** PATCH request with optional body *) 189 185 190 186 val delete : 191 187 (_ Eio.Time.clock, _ Eio.Net.t) t -> ··· 289 285 ]} 290 286 *) 291 287 288 + (** {2 Posting JSON Data} 289 + {[ 290 + let session = Session.create ~sw env in 291 + let json_str = {|{"name": "John", "age": 30}|} in 292 + let response = Session.post session 293 + ~body:(Body.json json_str) 294 + "https://api.example.com/users" in 295 + (* Response handling *) 296 + ]} 297 + *) 298 + 292 299 (** {2 With Authentication} 293 300 {[ 294 301 let session = Session.create ~sw env in ··· 307 314 308 315 (* Login - cookies will be saved *) 309 316 let login = Session.post session 310 - ~form:["username", "user"; "password", "pass"] 317 + ~body:(Body.form ["username", "user"; "password", "pass"]) 311 318 "https://example.com/login" in 312 319 313 320 (* Access protected resource - cookies are automatically included *)