This repository contains some RESTful API endpoint examples implemented in both:
There are 2 examples for each framework:
- Very simple APIs to echo the message provided and
- A simple credit risk modelling example (which uses some synthetically generated data to mimic a portfolio of home fixed and variable rate consumer home loans) with APIs to:
- train the model using the synthetic data with 20% of the sample used for testing (
/train
) - predict the probability of default using specific features in the data (
/predict
) and - there is also an example of a simple healthcheck for the API (
/healthcheck
)
The credit risk modelling examples require data to train/test the logistic regression example model. Some brief background on the modelling is shown here docs/credit_modelling.md.
For both frameworks, in a local deployment, the endpoints are accessed at:
http://localhost:8000/endpoint_name
.
A comparison of the two frameworks is available in docs/compare_plumber_fastapi.md.
The R examples use the Plumber
package to create API endpoints. These examples demonstrate:
- Basic endpoint creation for displaying a simple message (
simple.R
andrun_simple.R
) - Credit risk modelling endpoints
The Python examples use the FastAPI
framework to create endpoints by decorating methods. These examples showcase:
- Basic endpoint creation for displaying a simple message (
simple.py
andsimple.ipynb
) - Credit risk modelling endpoints
This data is generated in a Jupyter notebook in Python using the Faker package with the aim to produce a representative set of data. Note that only a sub-set of features
is used in the modelling.
Each example includes auto-documentation via http://localhost:8000/docs
for the R/Plumber APIs and
http://localhost:8000/docs
for the Python/FastAPI versions.
Additional documentation also describes how to set up and run the API.
See docs/api_testing.md.
- Clone this repository:
- Navigate to the desired example directory.
- Follow the instructions in each subdirectory to set up and run the examples.
- R (version 4.0+) for Plumber examples
- Python (version 3.7+) for FastAPI examples - see
pyproject.toml
for other environment details
There are Dockerfiles supplied for both frameworks which an indicative set ot commands to build the containers.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.