Production REST API for the Farmer Advisory Agent. Built with FastAPI.
This is the backend โ the Streamlit app is the demo layer. Real products need APIs.
pip install -r requirements.txt
uvicorn api.main:app --reloadOpen http://localhost:8000/docs for Swagger UI (auto-generated API docs).
| Method | Endpoint | Description |
|---|---|---|
| GET | /crops |
List all crops |
| GET | /crops/{name} |
Get crop details (rice, wheat, cotton...) |
| GET | /schemes |
List all schemes |
| GET | /schemes/{key} |
Get scheme details (pm_kisan, ayushman...) |
| GET | /schemes/search?q=loan |
Search schemes by keyword |
| GET | /weather/{location} |
Get weather + farming advisory |
| POST | /chat |
Ask any farming question (requires API key) |
| GET | /docs |
Swagger UI |
| GET | /redoc |
ReDoc |
| GET | /openapi.json |
OpenAPI schema |
pip install httpx
python tests/test_api.py12 tests covering all endpoints, error handling, and schema validation.
- Read
api/main.pyโ see how routes, models, and responses work - Open
/docsโ try the interactive Swagger UI - Run tests โ see how TestClient works
- TODO: Add API key authentication (FastAPI security)
- TODO: Add rate limiting (slowapi)
- TODO: Add response caching (Redis)
- TODO: Add request logging
- TODO: Add Dockerfile
- TODO: Deploy to Railway/Fly.io
- TODO: Add monitoring (Prometheus metrics)
- TODO: Add database (PostgreSQL) for analytics
Scaffolded with AI, extended with domain expertise. See BUILDING.md in the parent farmer-advisory-agent repo.
