crul (version 0.9.0)

ok: check if a url is okay

Description

check if a url is okay

Usage

ok(x, status = 200L, info = TRUE, ...)

Arguments

x

either a URL as a character string, or an object of class HttpClient

status

(integer) an HTTP status code, must be an integer. By default this is 200L, since this is the most common signal that a URL is okay, but there may be cases in which your URL is okay if it's a 201L, or some other status code.

info

(logical) in the case of an error, do you want a message() about it? Default: TRUE

...

args passed on to HttpClient

Value

a single boolean, if TRUE the URL is up and okay, if FALSE it is down.

Details

We internally verify that status is an integer and in the known set of HTTP status codes, and that info is a boolean

Examples

Run this code
# NOT RUN {
# 200
ok("https://google.com") 
# 200
ok("https://httpbin.org/status/200")
# 404
ok("https://httpbin.org/status/404")
# doesn't exist
ok("https://stuff.bar")
# doesn't exist
ok("stuff")

# with HttpClient
z <- crul::HttpClient$new("https://httpbin.org/status/404", 
 opts = list(verbose = TRUE))
ok(z)
# }

Run the code above in your browser using DataLab