init
This commit is contained in:
commit
09a564f792
7 changed files with 587 additions and 0 deletions
162
README.md
Normal file
162
README.md
Normal file
|
@ -0,0 +1,162 @@
|
|||
# Static2API
|
||||
|
||||
A simple FastAPI application that automatically exposes CSV and JSON files as API endpoints.
|
||||
|
||||
## Features
|
||||
|
||||
- Automatically creates API endpoints for CSV and JSON files in the `source` directory
|
||||
- Files are accessible via `/api/{filename}` endpoints
|
||||
- New files are detected automatically without restarting the server
|
||||
- Runs in a secure container with Docker or Podman
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Option 1: Run with Python
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Run the application
|
||||
uvicorn main:app --reload
|
||||
```
|
||||
|
||||
The API will be available at: http://localhost:8000
|
||||
|
||||
### Option 2: Run with Docker/Podman
|
||||
|
||||
Use the provided script to run the application in a container:
|
||||
|
||||
```bash
|
||||
# Make the script executable
|
||||
chmod +x run_container.sh
|
||||
|
||||
# Run the container
|
||||
./run_container.sh
|
||||
```
|
||||
|
||||
The API will be available at: http://localhost:8000
|
||||
|
||||
## API Endpoints
|
||||
|
||||
- `GET /` - Welcome message
|
||||
- `GET /api/{filename}` - Access data from files in the source directory
|
||||
|
||||
Example:
|
||||
- `GET /api/contacts` - Returns data from `source/contacts.csv`
|
||||
- `GET /api/users` - Returns data from `source/users.json`
|
||||
|
||||
## Sample Responses
|
||||
|
||||
### CSV Example (from contacts.csv)
|
||||
|
||||
```bash
|
||||
curl http://localhost:8000/api/contacts
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
[
|
||||
{
|
||||
"location": "dortmund",
|
||||
"contact": "achim"
|
||||
},
|
||||
{
|
||||
"location": "madrid",
|
||||
"contact": "santos"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### JSON Example (from users.json)
|
||||
|
||||
```bash
|
||||
curl http://localhost:8000/api/users
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"users": [
|
||||
{
|
||||
"name": "John",
|
||||
"email": "john@example.com"
|
||||
},
|
||||
{
|
||||
"name": "Jane",
|
||||
"email": "jane@example.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Adding New Files
|
||||
|
||||
1. Place CSV or JSON files in the `source` directory
|
||||
2. Files will be automatically accessible via `/api/{filename}`
|
||||
3. No restart required
|
||||
|
||||
## File Format Support
|
||||
|
||||
- CSV files: Must have a header row with column names
|
||||
- JSON files: Must contain valid JSON data
|
||||
|
||||
## Manual Container Setup
|
||||
|
||||
### Docker
|
||||
|
||||
```bash
|
||||
# Build the image
|
||||
docker build -t static2api:latest .
|
||||
|
||||
# Run the container
|
||||
docker run --name static2api \
|
||||
-p 8000:8000 \
|
||||
-v "./source":/home/appuser/app/source \
|
||||
--security-opt no-new-privileges:true \
|
||||
--cap-drop ALL \
|
||||
--user 1000:1000 \
|
||||
-d static2api:latest
|
||||
```
|
||||
|
||||
### Podman
|
||||
|
||||
```bash
|
||||
# Build the image
|
||||
podman build -t static2api:latest .
|
||||
|
||||
# Run the container
|
||||
podman run --name static2api \
|
||||
-p 8000:8000 \
|
||||
-v "./source":/home/appuser/app/source:Z \
|
||||
--security-opt no-new-privileges:true \
|
||||
--cap-drop ALL \
|
||||
--user 1000:1000 \
|
||||
-d static2api:latest
|
||||
```
|
||||
|
||||
## Container Management
|
||||
|
||||
### View Logs
|
||||
|
||||
```bash
|
||||
docker logs static2api
|
||||
# or
|
||||
podman logs static2api
|
||||
```
|
||||
|
||||
### Stop Container
|
||||
|
||||
```bash
|
||||
docker stop static2api
|
||||
# or
|
||||
podman stop static2api
|
||||
```
|
||||
|
||||
### Remove Container
|
||||
|
||||
```bash
|
||||
docker rm static2api
|
||||
# or
|
||||
podman rm static2api
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue