Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# mtcars as as service
# Create a JSON API for your data with GitHub + Blockspring
# This script will filter rows of mtcars based on API parameters
# import relevant libraries
# Get data from GitHub
mtcars_raw <- tempfile()
mtcars_raw, method = "curl", quiet = TRUE)
mtcars_github <- read.csv(mtcars_raw)
# Read values from Blockspring API and filter data accordingly.
mtcars_result <- filter(mtcars_github,
mpg >= mpg_min, mpg <= mpg_max,
cyl >= cyl_min, cyl <= cyl_max,
disp >= disp_min, disp <= disp_max,
hp >= hp_min, hp <= hp_max,
drat >= drat_min, drat <= drat_max,
wt >= wt_min, wt <= wt_max,
qsec >= qsec_min, qsec <= qsec_max,
vs >= vs_min, vs <= vs_max,
am >= am_min, am <= am_max,
gear >= gear_min, gear <= gear_max,
carb >= carb_min, carb <= carb_max)
# cat() the result so only pure JSON is returned from the POST request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.