Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b5827e

Browse files
authored
Merge pull request#45 from hadley/request-construction
Simplify request construction
2 parentsc81b388 +b8146eb commit4b5827e

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

‎R/utils.r‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,18 @@ make_request <- function(hostname, params, req_method = c("GET", "POST")) {
5050
.return<-utils::head(params[[".return"]],1L) %||%""
5151
params[[".return"]]<-NULL
5252

53-
if (req_method=="GET") {#
54-
53+
req<-httr2::request(paste0("https://",hostname))|>
54+
httr2::req_method(req_method)|>
55+
httr2::req_auth_bearer_token(token=.token$accessJwt)|>
56+
httr2::req_error(body=error_parse)
57+
58+
if (req_method=="GET") {
5559
all_params<- flatten_query_params(params)
56-
57-
resp<-list(
58-
scheme="https",
59-
hostname= dirname(hostname),
60-
path= basename(hostname),
61-
query= as.list(all_params)
62-
)|>
63-
structure(class="httr2_url")|>
64-
httr2::url_build()|>
65-
httr2::request()|>
66-
httr2::req_method("GET")|>
67-
httr2::req_auth_bearer_token(token=.token$accessJwt)|>
68-
httr2::req_error(body=error_parse)|>
69-
httr2::req_perform()
60+
req<-httr2::req_url_query(req,!!!all_params)
7061
}elseif (req_method=="POST") {
71-
resp<-httr2::request(glue::glue("https://{hostname}"))|>
72-
httr2::req_method("POST")|>
73-
httr2::req_auth_bearer_token(token=.token$accessJwt)|>
74-
httr2::req_body_json(params)|>
75-
httr2::req_error(body=error_parse)|>
76-
httr2::req_perform()
62+
req<-httr2::req_body_json(req,params)
7763
}
64+
resp<-httr2::req_perform(req)
7865

7966
if(.return%in% c("","json")){
8067
if(length(resp$body)){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp