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

Please assist with AOTH code snippet? #21

Open
tobefreeman opened this issue Jun 16, 2020 · 3 comments
Open

Please assist with AOTH code snippet? #21

tobefreeman opened this issue Jun 16, 2020 · 3 comments

Comments

@tobefreeman
Copy link

Dear Scott,

We are seeking to use your request package for an authenticated call to Swagger.

Would it be possible for you send a code snippet, indicating how to pass the API Key.

Help much appreciated.

Kind regards,
Tobe

@sckott
Copy link
Owner

sckott commented Jun 16, 2020

@tobefreeman thanks for your question. it depends on how swagger expects the key to be passed. Should it be as a query parameter, or as a header? Or some other way?

@tobefreeman
Copy link
Author

tobefreeman commented Jun 17, 2020 via email

@sckott
Copy link
Owner

sckott commented Jun 17, 2020

here's an example using the service at https://httpbin.org that many use to test packages like this one, so you can see what the different parts do.

peep lets you look at the query before the query is executed. Remove peep to execute the query

api('https://httpbin.org/get') %>%
  api_query(query = "foobar") %>%
  api_config(verbose()) %>%
  api_headers(`x-api-Key` = "your-key") %>%
  peep

#> <http request>
#>   url: https://httpbin.org/get
#>   paths:
#>   query: query=foobar
#>   body:
#>   paging:
#>   headers:
#>     x-api-Key: your-key
#>   rate limit:
#>   retry (n/delay (s)): /
#>   error handler:
#>   write:
#>   config:
#>     verbose: TRUE
api('https://httpbin.org/get') %>%
  api_query(query = "foobar") %>%
  api_config(verbose()) %>%
  api_headers(`x-api-Key` = "your-key")

#> -> GET /get?query=foobar HTTP/1.1
#> -> Host: httpbin.org
#> -> User-Agent: libcurl/7.70.0 r-curl/4.3 httr/1.4.1 request/0.1.6.91
#> -> Accept-Encoding: deflate, gzip
#> -> Accept: application/json, text/xml, application/xml, */*
#> -> x-api-Key: your-key
#> ->
#> <- HTTP/1.1 200 OK
#> <- Date: Wed, 17 Jun 2020 18:40:55 GMT
#> <- Content-Type: application/json
#> <- Content-Length: 965
#> <- Connection: keep-alive
#> <- server: istio-envoy
#> <- access-control-allow-origin: *
#> <- access-control-allow-credentials: true
#> <- x-envoy-upstream-service-time: 7
#> <-
#> $args
#> $args$query
#> [1] "foobar"
#> 
#> 
#> $headers
#> $headers$Accept
#> [1] "application/json, text/xml, application/xml, */*"
#> 
#> $headers$`Accept-Encoding`
#> [1] "deflate, gzip"
#> 
#> $headers$`Content-Length`
#> [1] "0"
#> 
#> $headers$Host
#> [1] "httpbin.org"
#> 
#> $headers$`User-Agent`
#> [1] "libcurl/7.70.0 r-curl/4.3 httr/1.4.1 request/0.1.6.91"
#> 
#> $headers$`X-Amzn-Trace-Id`
#> [1] "Root=1-5eea63b7-f0d4a45035c2f7f82dfed920"
#> 
#> $headers$`X-Api-Key`
#> [1] "your-key"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants