Skip to main content

Using the REST API

The REST API provides programmatic access to the linear regressor pipeline, allowing you to train models and make predictions.

Getting Started​

Local API Setup​

Start the API locally:

# Using Make
make run-api

# Using Poetry
poe run-api

Docker API Setup​

  1. Build and deploy with Docker:
# Build the Docker image
make docker-build

# Deploy the API container
make docker-deploy-api

API Base URL​

Local: http://localhost:8000
Docker: http://localhost:8000

Endpoints​

Model information

Prediction

Make Single Prediction

POST /predict

Example request

import requests
import pandas as pd

# Prepare data
data = {
"data": {
"feature1": [1.0],
"feature2": [2.0]
}
}

# Make prediction
response = requests.post(
"http://localhost:8000/predict",
json=data
)

print(response.json())

Batch Prediction

POST /predict_batch

Example request

import requests
import pandas as pd

# Read CSV file
df = pd.read_csv("./data/sample.csv")

# Prepare data
data = {
"data": df.to_dict(orient="list")
}

# Make batch predictions
response = requests.post(
"http://localhost:8000/predict_batch",
json=data
)

print(response.json())

Train models

POST /train

Example request

import requests
import pandas as pd

# Read training data
df = pd.read_csv("./data/sample.csv")

# Prepare training data
data = {
"data": df.to_dict(orient="list")
}

# Train model
response = requests.post(
"http://localhost:8000/train",
json=data
)

print(response.json())

Docker Management​

Stop the API

make docker-stop-api

Remove the API container

make docker-down-api