Skip to content

Commit

Permalink
Merge branch 'feature/API' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbrig committed Mar 31, 2023
2 parents 09e15f4 + 1585dd3 commit 9e98664
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions inst/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM rocker/r-ver

# FROM rstudio/plumber

# sysreqs - pak::pkg_system_requirements("plumber", "ubuntu", "20.04")
RUN apt-get install -y libcurl4-openssl-dev \
apt-get install -y libssl-dev \
apt-get install -y libsodium-dev \
apt-get install -y libicu-dev \
apt-get install -y make \
apt-get install -y zlib1g-dev

# R packages
RUN R -e "install.packages('plumber')"
RUN R -e "install.packages('remotes')"
RUN R -e "remotes::install_github('jimbrig/lossrx')"

# Copy API
COPY plumber.R /

# Expose Port 80 to Traffic
EXPOSE 80

# Entrypoint
ENTRYPOINT ["R", "-e", "pr <- plumber::plumb('plumber.R'); pr$run(host='0.0.0.0', port=80)"]
Empty file added inst/api/README.md
Empty file.
Empty file added inst/api/openapi.yml
Empty file.
31 changes: 31 additions & 0 deletions inst/api/plumber.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# This is a Plumber API. You can run the API by clicking
# the 'Run API' button above.
#
# Find out more about building APIs with Plumber here:
#
# https://www.rplumber.io/
#

library(plumber)

#* @apiTitle Loss Reserving API
#* @apiDescription An Actuarial API for dealing with Loss Reserving Data and Workflows.


# Utility Endpoints -------------------------------------------------------

#* Echo back the input
#* @param msg The message to echo
#* @get /echo
function(msg = "") {
list(msg = paste0("The message is: '", msg, "'"))
}

# Programmatically alter your API
#* @plumber
function(pr) {
pr %>%
# Overwrite the default serializer to return unboxed JSON
pr_set_serializer(serializer_unboxed_json())
}
2 changes: 2 additions & 0 deletions inst/api/run_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker build -t lossreservingapi:latest .
docker run -p 80:80 -d lossreservingapi:latest

0 comments on commit 9e98664

Please sign in to comment.