HTTP types: headers, status codes, methods, bodies, MIME types
0
fork

Configure Feed

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

ocaml-http: fix README quick start against the real API

The block was off by several names: bare [Body] / [Headers] / [Mime]
without [open Http], a positional [Multipart.name] field that
actually lives in [Body.part], a [Mime.pdf] constant that doesn't
exist, [Body.json] called with [Jsont.Object] instead of
[Json.Value.object'], and missing [nox-json] / [eio*] mdx libraries.

Add [open Http], reach into [Json.Value.(...)] to construct the JSON
tree, use [Mime.of_string "application/pdf"], and label the part
record with [Body.name]. Wrap the multipart upload as [let upload
~fs = ...] since it needs an [Eio] FS.

+19 -11
+18 -10
README.md
··· 47 47 ## Quick Start 48 48 49 49 ```ocaml 50 - (* Build a JSON body *) 51 - let body = Body.json Jsont.(Object ([ ("name", String "Alice") ], Meta.none)) 50 + open Http 52 51 53 - (* Build headers *) 52 + (* Build a JSON body. *) 53 + let body = 54 + Json.Value.( 55 + Body.json (object' [ member (name "name") (string "Alice") ])) 56 + 57 + (* Build headers. *) 54 58 let headers = 55 59 Headers.empty 56 60 |> Headers.set `Content_type "application/json" 57 61 |> Headers.set `Authorization "Bearer token" 58 62 |> Headers.set (`Other "X-Request-Id") "abc123" 59 63 60 - (* Multipart file upload *) 61 - let body = 62 - Body.multipart [ 63 - { name = "file"; filename = Some "doc.pdf"; 64 - content_type = Mime.pdf; 65 - content = `File Eio.Path.(fs / "doc.pdf") }; 66 - ] 64 + (* Multipart file upload. *) 65 + let upload ~fs = 66 + Body.multipart 67 + [ 68 + { 69 + Body.name = "file"; 70 + filename = Some "doc.pdf"; 71 + content_type = Mime.of_string "application/pdf"; 72 + content = `File Eio.Path.(fs / "doc.pdf"); 73 + }; 74 + ] 67 75 ``` 68 76 69 77 ## License
+1 -1
dune
··· 4 4 5 5 (mdx 6 6 (files README.md) 7 - (libraries nox-http)) 7 + (libraries nox-http nox-json eio eio.unix))