YOURLS API with R

YOURLS API with R
Page content

Goal: Create multiple, and trackable, short URLs that point to the same place

Tools: YOURLS, R

Steps:

Installing YOURLS is very easy, particularly if you do it with docker.

  1. A container for the database:
docker run --name yourlsmysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
  1. A container for YOURLS:
docker run --name yourls -d \
-e YOURL_USER='admin' \
-e YOURL_PASSWORD='mysecretpassword' \
-e YOURLS_SITE='http://sh.tld' \
--link yourlsmysql:mysql bios/docker-yourls

To use the web-interface, you need to go to your site. For example, http://sh.tld/admin

With R, you can use the R package that I created

# install.packages("yourls", repos = "https://cran.ignacio.website", type = "source") 
library(yourls)

apikey <- secret::get_secret("apikey", vault = file.path(system.file(package = "yourls"), "vault"))


short_url <- shortenurl(apikey = apikey, 
                        url = "https://blog.ignacio.website/post/yourls-api-with-r")

short_url



yourls::urlstats(apikey = apikey, 
                 url = short_url)

In the future, I may try to improve the yourls::urlstats function.