httr icon indicating copy to clipboard operation
httr copied to clipboard

PATCH is broken

Open ksonda opened this issue 4 years ago • 0 comments

I believe PATCH is broken. Below is a reprex where a POST from httr works, the PATCH does not, and the PATCH from httr2 does work.

library(jsonlite)
library(httr)
library(httr2)


#url <- "https://ogc-demo.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Things"
# b <- list(name = "my name", description = "first draft")


# response <- httr::POST(url = url, body = jsonlite::toJSON(b, auto_unbox=TRUE_, encode = "json")
# response
# This POST creates https://ogc-demo.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Things(2072)

jsonlite::fromJSON("https://ogc-demo.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Things(2072)")

# Now let's PATCH with httr
url2 <- "https://ogc-demo.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Things(2072)"
b2 <- list(name = "my name",
               description = "second draft")
response <- httr::PATCH(url = url, body = jsonlite::toJSON(b2, auto_unbox=TRUE), encode = "json")

# (we get error 400)

# Now let's PATCH with httr2
req <- request(url2) %>% #sets URL
  req_body_json(b2) %>%  # adds list-body, formatting as JSON
  req_method("PATCH") 

req_perform(req)

ksonda avatar Feb 07 '22 18:02 ksonda