For creating custom APIs
- Python 3.11+ on macOS (
python3 --version
)
cd practice-api
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
uvicorn app.main:app --reload
- Open your browser to
http://127.0.0.1:8000
for the welcome message - Health check:
http://127.0.0.1:8000/health
- Interactive docs:
http://127.0.0.1:8000/docs
Example request:
curl -X POST "http://127.0.0.1:8000/echo" \
-H "Content-Type: application/json" \
-d '{"message": "hello"}'
practice-api/
app/
__init__.py
main.py
requirements.txt
README.md
- Add new endpoints in
app/main.py
- Split routes into modules (e.g.,
app/routers/
) as the API grows - Add tests with
pytest
Set DROPBOX_ACCESS_TOKEN
in your environment (User or App token with files.content.read scope).
Run locally:
export DROPBOX_ACCESS_TOKEN=YOUR_TOKEN
uvicorn app.main:app --reload
Request:
curl -X POST "http://127.0.0.1:8000/dropbox/pdfs" \
-H "Content-Type: application/json" \
-d '{"folder_path": "/path/in/dropbox"}'
Response:
{ "files": ["a.pdf", "nested/b.pdf"], "count": 2 }
On Render, add an Environment Variable DROPBOX_ACCESS_TOKEN
in the service settings.
- Push this repo to GitHub.
- Sign in to Render and create a new Web Service from your repo.
- Environment: Python
- Build Command:
pip install -r requirements.txt
- Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT
- Health Check Path:
/health
- After deploy, your base URL will be something like
https://practice-api.onrender.com
.
- Method:
GET
- URL:
https://practice-api.onrender.com/health
- Expect:
{"status":"ok"}
and HTTP 200
For POST /echo
in n8n:
- Method:
POST
- URL:
https://practice-api.onrender.com/echo
- Send: JSON body
{"message":"hello"}
- Headers:
Content-Type: application/json