Creating a microservice

Preparing a microservice in R

In this section, we will prepare a microservice without any dependency in R. The sample microservice will get two input parameters a and b and return the sum of the two. For a microservice with dependency in R, please refer Appendix 1. (Advanced) Preparing microservices with dependencies in R.

  1. Open a text editor and copy & paste the following
run <- function(data) {
  return(list(sum=data$a + data$b))
}
  1. Save the file as knowledge.R in a directory of your choice.

Preparing a microservice in Python

In this section, we will prepare a microservice without any dependency in Python. For a microservice with dependencies in Python, please refer Appendix 2. (Advanced) Create a microservice with dependencies in Python.

  1. Open a text editor and copy & paste the following
def run(data):
    return {"sum": data["a"] + data["b"]}
  1. Save the file as knowledge.py in a directory of your choice.

Creating a runnable

  1. Log in and create “Runnables” on the top menu
_images/create_runnable_1.png
  1. Click “Create Runnable” on the top right
_images/create_runnable_2.png
  1. Enter a title, choose the language and select knowledge file (knowledge.R or knowledge.py), requirement file (packrat.lock or requirement.txt) and miscellaneous files (please refer Appendices 1 and 2 for more information on the requirement and miscellaneous files). Then click “Create”
_images/create_runnable_3.png
  1. Click the title of the new runnable to move to the runnable’s detail page. Wait until the status of the first version changes from building to ready.
_images/create_runnable_4.png

Making the first run request

  1. Click the title of the new runnable created
_images/make_run_request_1.png
  1. Click “View Runs” button
_images/make_run_request_2.png
  1. Click “Run Runnable”
_images/make_run_request_3.png
  1. Enter input in JSON that your microservices expect. In our case we need to provide an object with two keys a and b. Then click “Run” button
_images/make_run_request_4.png
  1. This will redirect you to a list of recent runs where you can find the output
_images/make_run_request_5.png