Project Structure

 
D:\python-apps\fastapi-service\

│
├── app\
│   ├── main.py
│   ├── endpoints\
│   │   ├── hello_world.py
│
├── requirements.txt

Install Dependencies

 
python -m pip install --upgrade pip
python3 -m venv myenv

.\myenv\Scripts\activate

(myenv) pip install fastapi uvicorn
(myenv) pip freeze > requirements.txt

FastAPI Code

app/main.py
 
from fastapi import FastAPI
from app.endpoints import hello_world

app = FastAPI(title="My Automations API")

# Register hello_world router
app.include_router(hello_world.router, prefix="/hello", tags=["Hello World"])
app/endpoints/hello_world.py
 
from fastapi import APIRouter

router = APIRouter()

@router.get("/")
async def hello():
    return {"message": "Hello from FastAPI!"}

Run the API

From D:\python-apps\fastapi-service\:
 
(myenv)       
python -B -m uvicorn app.main:app --host 0.0.0.0 --port 8000
    # B tells Python not to write __pycache__
Now your API is live at: http://localhost:8000/hello/ Test in browser or with curl: curl http://localhost:8000/hello/ Expected response: {"message": "Hello from FastAPI!"}

Client Example

Snippet using file_get_contents (or you can use curl for more control):
  
php

if (!empty($_POST['btn_process'])) {
    $url = "http://localhost:8000/hello/";
    $response = file_get_contents($url);
    $data['message'] = $response;
}