-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookbook Send a POST/PATCH Request w/ Authentication #2534
base: main
Are you sure you want to change the base?
Conversation
data/cookbook/make-http-post-request-bearer-auth/00-cohttp_lwt.ml
Outdated
Show resolved
Hide resolved
let headers = | ||
Header.init () | ||
|> fun h -> | ||
Header.add h "Accept" "application/vnd.github+json" | ||
|> fun h -> | ||
Header.add h "Authorization" "Bearer <your token goes here>" | ||
|> fun h -> Header.add h "X-GitHub-Api-Version" "2022-11-28" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier to read using a local definition such as:
let header_add s1 s2 h = Header.add h s1 s2 in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I updated it to do what you are saying. I'm very new to Ocaml so please let me know if this isn't what you meant.
>>= fun (response, body) -> | ||
let code = response |> Response.status |> Code.code_of_status in | ||
body |> Cohttp_lwt.Body.to_string >|= fun body -> code, body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't binding operators available instead of binary operators there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. I'm new to this but using binding operators does make it make much easier to read! Thank you.
Co-authored-by: Cuihtlauac Alvarado <cuihtlauac@users.noreply.github.com>
Added task to web programming section to show how to send data via a POST request. I wondered if it would be beneficial to have a section dedicated to working with REST APIs in general?
Will add cookbook examples that send data with POST and returns a response.