get respomse in r

To get a response in R, you can use the built-in functions provided by various packages. One of the most commonly used packages for making HTTP requests is httr. Here is an example of how to make an HTTP GET request to a URL and extract the response:

main.r
library(httr)

response <- GET("https://jsonplaceholder.typicode.com/posts/1")

# print the status code
response$status_code

# print the content of the response
content(response)
180 chars
10 lines

In this example, we're making a GET request to an API endpoint and storing the response in response variable. We then print the status code using response$status_code and the content of the response using content(response). You can modify this code as per your requirements and use different HTTP methods like POST, PUT, DELETE, etc.

related categories

gistlibby LogSnag