Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

ggsmith842
Copy link
Contributor

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.

@ggsmith842 ggsmith842 marked this pull request as draft June 20, 2024 14:11
@ggsmith842 ggsmith842 marked this pull request as ready for review June 22, 2024 02:41
@ggsmith842 ggsmith842 changed the title Cookbook Send a POST Request w/ Authenitcation Cookbook Send a POST/PATCH Request w/ Authenitcation Jun 22, 2024
data/cookbook/tasks.yml Outdated Show resolved Hide resolved
data/cookbook/tasks.yml Outdated Show resolved Hide resolved
Comment on lines 52 to 58
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"
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Comment on lines 62 to 64
>>= fun (response, body) ->
let code = response |> Response.status |> Code.code_of_status in
body |> Cohttp_lwt.Body.to_string >|= fun body -> code, body
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@ggsmith842 ggsmith842 changed the title Cookbook Send a POST/PATCH Request w/ Authenitcation Cookbook Send a POST/PATCH Request w/ Authentication Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants