README.md

useapi

lifecycle

πŸ“©πŸ“¨ A workflow for building API wrapper/client packages in R.

Installation

You can install from Github with:

## install from github
devtools::install_github("mkearney/useapi")

Example

This is a basic example of how to create a new API client package:

## create example package
create_api_package(path = "/tmp/useapitest", 
  site = "Use API Test",
  base_url = "https://api.useapitest.com/v1")
#> βœ” Changing active project to '/private/tmp/useapitest'
#> βœ” Creating 'R/'
#> βœ” Creating 'man/'
#> βœ” Writing 'DESCRIPTION'
#> βœ” Writing 'NAMESPACE'
#> Writing R/api.R ++++++++++++++++++++++++++++++++++++++++++++++++++++ 100%
#> Writing R/utils.R ++++++++++++++++++++++++++++++++++++++++++++++++++ 100%
#> Writing R/oauth.R ++++++++++++++++++++++++++++++++++++++++++++++++++ 100%
#> βœ” Adding 'httr' to Imports field in DESCRIPTION
#> ● Refer to functions with `httr::fun()`
#> βœ” Adding 'jsonlite' to Imports field in DESCRIPTION
#> ● Refer to functions with `jsonlite::fun()`
#> βœ” Adding 'tibble' to Imports field in DESCRIPTION
#> ● Refer to functions with `tibble::fun()`
#> Updating useapitest documentation
#> Loading useapitest
#> Updating roxygen version in /private/tmp/useapitest/DESCRIPTION
#> Writing NAMESPACE
#> Writing NAMESPACE
#> Writing useapitest_api_get.Rd
#> Writing useapitest_api_post.Rd
#> Writing useapitest_token.Rd
#> Writing useapitest_as_tbl.Rd
#> Installing useapitest
#> '/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file  \
#>   --no-environ --no-save --no-restore --quiet CMD INSTALL  \
#>   '/private/tmp/useapitest'  \
#>   --library='/Library/Frameworks/R.framework/Versions/3.5/Resources/library'  \
#>   --install-tests
#> 
#> Reloading installed useapitest

See the example useapitest package here.

## load new package
library(useapitest)

## create request URL
useapitest:::useapitest_api_call(path = "rstats/apidevtools", 
  n = 20, include_entities = TRUE)
#> [1] "https://api.useapitest.com/v1/rstats/apidevtools?n=20&include_entities=TRUE"

It’s all ready to send and receive HTTP requests1:

## send GET request
r <- useapitest_api_get(path = "rstats/apidevtools", n = 20)

## view data
useapitest_as_tbl(r)

1 Note: The example is a fictional website/application and thus will create an error due to an unresolveable host domain.



mkearney/useapi documentation built on May 22, 2019, 3:51 p.m.