REST API endpoints deployed using Workbench are secure and only accessible to users that you’ve shared the deployment with or users that have generated a token that can be used to query the REST API endpoint outside of Workbench.
Install Tranquilizer
Open a session and run the following command to install Tranquilizer:- Functions - Defined sections of code that perform specific tasks.
- Type Hints - A method to statically indicate the type of a value within your Python code.
- Docstrings - Comments in the code that document what a given function does.
Tranquilizer reads the function’s docstring to automatically generate Swagger documentation for the REST API.
Decorate your function
Decorated functions are identified by the Tranquilizer server. These functions are executed when HTTP requests are made to the server. Here is an example of a temperature conversion function with the tranquilizer decoration:When the Tranquilizer server starts, the entire Jupyter Notebook is executed. Consider carefully how you arrange operations that are heavy on CPU or memory usage, like reading data or loading models. Computations for reusable objects should be performed only once, rather than every time the function is called.
Add the command
With tranquilizer downloaded and your function decorated, you must now prepare the deployment command. Open youranaconda-project.yml
file and add the following code:
Make sure your notebook file name is spelled correctly! If it is not, your commands will not work.
Commit and deploy
Choose a unique URL for your deployment.
Verify deployment
Once the deployment has started, go to the deployment’s View page and use swagger to verify that the API performs the correct function.
Deploy a REST API with R
You can use the R Plumber package to build and deploy a REST API in R. Run the following command to installR Plumber
:
api.R
api.r
and run.R
scripts, add your command specification in the anaconda-project.yml
file:
run.R
script as follows:
run.R
script directly in the anaconda-project.yml
file: