Skip to contents

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.

Usage

cookie_endpoint_httr2(default_cookie_name = "therealshinyapps")

Arguments

default_cookie_name

Character. The name of the cookie to use if the user does not request a different cookie.

Value

The source code for a cookie endpoint as character.

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())