HTTP POST sends data from a client to a server for handling. Unlike GET, which retrieves data, POST is suited to submitting credentials, form choices, or model input features. A server can process the submitted values and return a result without exposing its implementation to the client. section 9.3.1
POST is useful when a data science workflow needs to move beyond a local notebook. A client can send customer inputs to a remote prediction service; server-side code can fetch needed features, run a model, and return a prediction. This separation lets another language or system use a Python-based model through an API. section 9.3.1
A practical POST endpoint has three parts:
- Define a route that accepts POST requests, such as a FastAPI endpoint at /churn/. section 9.3.2
- Specify the input fields and their types. A Pydantic model can parse and validate submitted feature values, including numeric conversions when needed. section 9.3.2
- Transform the inputs for the model, compute the prediction, and return a small response such as a churn probability. section 9.3.2
- Send the payload in JSON, a lightweight key-value format similar to a Python dictionary. section 9.3.2
Requesting a churn prediction
A Python client builds a JSON dictionary with total call minutes, call count, and customer-service calls, then uses requests.post() to send it to a local /churn endpoint. The endpoint validates the fields, creates model inputs, and returns JSON containing prob_of_churn. Launching the service with uvicorn makes the endpoint available while it runs. section 9.3.2
POST also drives web forms. A route can allow both GET and POST: GET renders the page, while POST runs only after a user submits form data. In a machine learning app, submitted feature and label selections can trigger training, generate test predictions, and prepare a CSV download. section 13.3.6
Listing 9.17 This code will launch an API to handle fetching predictions for the custom churn prediction model.
import sys #1
sys.path.append("../../")
from fastapi import FastAPI
from pydantic import BaseModel
import pandas as pd
import joblib
class ModelFeatures(BaseModel): #2
total_day_minutes: float
total_day_calls: int
num_customer_service_calls: int
model = joblib.load("../model_outputs/churn_model.sav") #3
app = FastAPI() #4
@app.post("/churn/") #5
async def get_churn_predictions( #6
features: ModelFeatures):
model_inputs = pd.DataFrame([features.total_day_calls, #7
features.total_day_minutes,
features.num_customer_service_calls]).transpose()
pred = model.clf.predict_proba(model_inputs)[0,1] #8
return {"prob_of_churn": pred} #9
This diagram shows the client-server boundary: a different language or system can make the request while Python handles prediction work on the server. section 9.3.1

















