Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary Plumber API Setup #29

Merged
merged 9 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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