Skip to content

Commit

Permalink
Update request code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsim committed Sep 30, 2024
1 parent d55b45f commit 9af18e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions source/partials/_request_example_js.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const url = '<%= url %>';
<% if body_json %>
const headers = {
'Content-Type': 'application/json'
},
};
const body = <%= body_json %>;
<% end %>

const response = await fetch(url, {
method: '<%= http_method %>',
<% if body_json %>
headers,
body: JSON.stringify(body),
body: JSON.stringify(body)
<% end %>
});

Expand Down
4 changes: 2 additions & 2 deletions source/partials/_request_example_py.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import requests
url = '<%= url %>'
<% if body_json %>
headers = {
"Content-Type": "application/json",
'Content-Type': 'application/json'
}
data = '<%= body_json %>'
data = '''<%= body_json %>'''
<% end %>

response = requests.<%= http_method.downcase %>(url<% if body_json %>, headers=headers, data=data<% end %>)
Expand Down
16 changes: 11 additions & 5 deletions source/partials/_request_example_r.md.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
```r
library(httr)

url <- '<%= url %>'
url <- "<%= url %>"
<% if body_json %>
body <- '<%= body_json %>'
body <- "<%= body_json %>"
<% end %>

response <- httr::<%= http_method.upcase %>(url<% if body_json %>,
body=body, encode='json',
<% if body_json %>
response <- <%= http_method.upcase %>(
url,
body = body,
encode = "json",
content_type("application/json")
<% end %>)
)
<% else %>
response <- <%= http_method.upcase %>(url)
<% end %>

output <- content(response)
```

0 comments on commit 9af18e4

Please sign in to comment.