Source code for a cookie endpoint that uses httr2
Source:R/cookie_endpoints.R
cookie_endpoint_httr2.Rd
Posit Cloud uses a cookie to identify the user. The output of this function can be used to add a "/cookie" endpoint to an api in order to allow users to easily extract their Posit Cloud cookie for your endpoint and use that cookie with the httr2 package.
Arguments
- default_cookie_name
Character. The name of the cookie to use if the user does not request a different cookie.
Examples
cookie_endpoint_httr2()
#> plumber::pr_get("/cookie", function(req) {
#> cookie_nm <- req$argsQuery[["cookie_name"]]
#> if (is.null(cookie_nm)) cookie_nm <- "therealshinyapps"
#> cookie_value <- req$cookies[[cookie_nm]]
#> glue::glue("httr2::req_headers(Cookie = '{cookie_nm}={cookie_value}')")
#> }, serializer = plumber::serializer_text())
cookie_endpoint_httr2("another_cookie_name")
#> plumber::pr_get("/cookie", function(req) {
#> cookie_nm <- req$argsQuery[["cookie_name"]]
#> if (is.null(cookie_nm)) cookie_nm <- "another_cookie_name"
#> cookie_value <- req$cookies[[cookie_nm]]
#> glue::glue("httr2::req_headers(Cookie = '{cookie_nm}={cookie_value}')")
#> }, serializer = plumber::serializer_text())