Build a RESTFUL API in minutes using R's Plumber | English Premier League Stats 2020/2021 Season
It is no longer news that Manchester City are EPL Champions for the 2020/2021 Season!
One thing for sure if that my Weekend morning won't be the same again... Well at least for a while.
As a fan, I decided to build a Restful API that captures all the key stats for this season. The Restful API has 3 endpoints that capture/define the stats. They are categorized as the following:
1) GET /EPLStrikers
2) GET /EPLDefenders
3) GET /EPLDiscipline
The recently discovered R's Plumber and it is excellent. It is nice for quick prototyping with out unnecessary complexity.
R Code EPLStats.R
#!/usr/bin/R library(plumber) library(magrittr) library(dplyr) library(reticulate) library(reticulate) library(magrittr) library(dplyr) #use_python("/root/.local/share/r-miniconda/envs/r-reticulate/bin/python3.6") use_virtualenv("r-shiny") pd <- import("pandas") nd <- import("numpy") #os <- import("os") #* @param EPLStrikers List of EPL Strikers (2020/2021 Season) #* Echo back the input #* @get /EPLStrikers function(EPLStrikers = ""){ url = "https://www.msn.com/en-au/sport/football/epl/player-stats" list = pd$read_html(url) list } #* @param EPLDefenders List of EPL Defenders (2020/2021 Season) #* Echo back the input #* @get /EPLDefenders function(EPLDefenders = ""){ urls = "https://www.msn.com/en-au/sport/football/epl/team-stats/sp-vw-teamdefense" lists = pd$read_html(urls) lists } #* @param EPLDiscipline List of EPL Disciplinary records (2020/2021 Season) #* Echo back the input #* @get /EPLDiscipline function(EPLDiscipline = ""){ url2 = "https://www.msn.com/en-au/sport/football/epl/team-stats/sp-vw-teamdiscipline" list2 = pd$read_html(url2) list2
}
In the above code, we were able to call our python interpreter using R's library reticulate. In the above code, each endpoint is configured for GET requests only on which the output by default is serialized in a Json format.
plumb(file='RStuff/EPLStats.R')$run()
Above, the library, comes "Batteries included" using to Swagger temporarily host and process the endpoints.
TopStrikers Endpoint
TopDefenders Endpoint
MostDisciplined Teams Endpoint
Interesting stuff, we successfully created three Endpoints using R's Plumber library. One can parse and scrape it for further analysis.
For a Production environment one could employ the use of a CI/CD tool, say Jenkins for Continuous Deployment and Docker for Container Orchestration.
Next week, I'll try to create interesting visuals in order to gain insight in to the almost concluded season. I generally like combining Sports and Data to gain insights that ordinarily could have been overlooked.