Skip to content

nirajNvr/fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Data Collector

A simple FastAPI application that collects data through a /append-data endpoint and stores it in a SQLite database.

Features

  • POST /append-data endpoint to submit data (name and value)
  • GET /health endpoint for health checks
  • Input validation using Pydantic
  • SQLite database for storage with SQLAlchemy ORM
  • Nginx configuration for reverse proxy
  • Simple HTML/JavaScript frontend
  • Basic logging and error handling

Project Structure

.
├── app
│   ├── __init__.py
│   ├── main.py
│   ├── database
│   │   ├── __init__.py
│   │   ├── database.py
│   │   ├── models.py
│   │   ├── schemas.py
│   │   └── data
│   │       └── app.db
│   └── static
│       └── index.html
├── nginx.conf
└── requirements.txt

Setup and Installation

1. Create and activate a virtual environment (optional but recommended)

python -m venv venv
venv\Scripts\activate

2. Install dependencies

pip install -r requirements.txt

3. Run the FastAPI application

uvicorn app.main:app --host 0.0.0.0 --port 8000

The application will be available at http://localhost:8000.

4. Setup Nginx (optional for production)

  1. Install Nginx if not already installed
  2. Copy the provided nginx.conf to your Nginx configuration directory
  3. Restart Nginx to apply the changes

Usage

Using the Web Interface

Open http://localhost:8000 in your browser to access the web interface.

Using curl

curl -X POST "http://localhost:8000/append-data" \
    -H "Content-Type: application/json" \
    -d '{"name": "example", "value": 42.5}'

Using JavaScript fetch

fetch('http://localhost:8000/append-data', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        name: 'example',
        value: 42.5
    }),
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

API Documentation

When the application is running, you can access the automatically generated API documentation at:

Running the Application

To terminate the currently running application, press Ctrl+C in the terminal where it's running.

To run the application again:

uvicorn app.main:app --host 0.0.0.0 --port 8000

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors