API for managing and querying mineral information built with FastAPI.
- CRUD operations for mineral data
- Advanced search filters
- Random mineral endpoint
- Comprehensive statistics
- Ready for deployment (PythonAnywhere, Caddy, etc.)
- OpenAPI documentation included
- Clone repository:
git clone https://github.com/mzums/mineralapi.git
cd mineralapi- Create virtual environment:
python -m venv venv
source venv/bin/activate # Linux/MacOS
venv\Scripts\activate # Windows- Install dependencies:
pip install fastapi uvicorn a2wsgi- Run development server:
uvicorn main:app --reload# Health check
curl http://mineralapi.mzums.hackclub.app/health
# Get all minerals
curl http://mineralapi.mzums.hackclub.app/minerals
# Get random mineral
curl http://mineralapi.mzums.hackclub.app/minerals/random
# Add new mineral
curl -X POST http://mineralapi.mzums.hackclub.app/minerals \
-H "Content-Type: application/json" \
-d '{"id":3,"name":"Diamond","chemical_composition":"C","hardness":10,"origin":"South Africa"}'
# Full API documentation available at:
https://mineralapi.mzums.hackclub.app/docs| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Service health check |
| GET | /minerals |
List all minerals with filters |
| GET | /minerals/{id} |
Get mineral by ID |
| GET | /minerals/random |
Get random mineral |
| GET | /stats |
Get mineral statistics |
| POST | /minerals |
Create new mineral |
| PUT | /minerals/{id} |
Update existing mineral |
| DELETE | /minerals/{id} |
Delete mineral |
class Mineral(BaseModel):
id: int
name: str
chemical_composition: str
hardness: float # Mohs scale
origin: str
color: Optional[str] = None
rarity: Optional[str] = None- Create
WSGIfile:
from main import app
from a2wsgi import ASGIMiddleware
application = ASGIMiddleware(app)- Install requirements:
pip install fastapi a2wsgi- Reload web app in control panel
uvicorn main:app --host 0.0.0.0 --port 8000MIT License. See LICENSE for details.
- Fork the repository
- Create feature branch (
git checkout -b feature/foo) - Commit changes (
git commit -am 'Add some foo') - Push to branch (
git push origin feature/foo) - Create new Pull Request
- Built with FastAPI
- Deployed on Hack Club Nest