-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
91 lines (63 loc) · 2.27 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
httping
=======
```{r echo=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>"
)
```
[![cran checks](https://badges.cranchecks.info/worst/httping.svg)](https://cloud.r-project.org/web/checks/check_results_httping.html)
[![R-check](https://github.com/sckott/httping/actions/workflows/R-check.yaml/badge.svg)](https://github.com/sckott/httping/actions/workflows/R-check.yaml)
[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/httping?color=C9A115)](https://github.com/metacran/cranlogs.app)
[![cran version](https://www.r-pkg.org/badges/version/httping)](https://cran.r-project.org/package=httping)
`httping` is a tiny R package to Ping urls to time requests. It's a port of the Ruby gem [httping](https://github.com/jpignata/httping).
## Install
CRAN stable version
```{r eval=FALSE}
install.packages("httping")
```
Development version from Github
```{r eval=FALSE}
install.packages("pak")
pak::pkg_install("sckott/httping")
```
```{r}
library("httping")
library("httr")
```
## Pass any httr request to time
A `GET` request
```{r}
GET("https://google.com") %>% time(count = 3)
```
A `POST` request
```{r}
POST("https://mockbin.com/request", body = "A simple text string") %>% time(count = 3)
```
The return object is a list with slots for all the `httr` response objects, the times for each request, and the average times. The number of requests, and
the delay between requests are included as attributes.
```{r}
res <- GET("http://google.com") %>% time(count = 3)
attributes(res)
```
Or print a summary of a response, gives more detail
```{r}
res %>% summary()
```
Messages are printed using `cat`, so you can suppress those using `verbose=FALSE`, like
```{r}
GET("https://google.com") %>% time(count = 3, verbose = FALSE)
```
## Ping an endpoint
This function is a bit different, accepts a url as first parameter, but can accept any args passed on to `httr` verb functions, like `GET`, `POST`, etc.
```{r}
"https://google.com" %>% ping()
```
Or pass in additional arguments to modify request
```{r}
"https://google.com" %>% ping(config = verbose())
```
## Meta
* Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.