Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geekidharsh/sample-flask-api
https://github.com/geekidharsh/sample-flask-api
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/geekidharsh/sample-flask-api
- Owner: geekidharsh
- Created: 2023-07-28T22:06:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-12T21:19:22.000Z (7 months ago)
- Last Synced: 2024-06-13T03:17:27.132Z (7 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flask API
## Gene Data Processor.
A Flask based API that provides two endpoints for data processing and health checks.
It processes data from a CSV file based on the specified timestamp and performs a health check to ensure that the API is running fine.## Endpoints
### Health Check - GET
- **URL**: `/health`
- **HTTP Method**: GET
- **Description**: This endpoint is used to verify if the API is running fine.- **Response**:
- Status: `200 OK`
- Content: JSON object containing the following keys:
- `status`: Status of the API (`"success"`)
- `message`: A message indicating the health status of the API.### Get Data - POST
- **URL**: `/getData`
- **HTTP Method**: POST
- **Description**: The API expects a JSON payload containing the timestamp to filter the data.
- **Request Payload**:
- Content: JSON object containing the following key:
- `timestamp`: A string in the format `"MM-DD-YYYY"`
- Sample:
- `{"timestamp": "07-02-2023"}`
- **Response**:
- If the data structure is valid and the timestamp is correct, the API responds with a success message and the processed data.
- Status: `200 OK`
- Content: JSON object containing the following keys:
- `status`: Status of the response
- `message`: A message indicating the processing status (`"Data processed successfully."`)
- `data`: A list of dictionaries representing the processed data for the specified timestamp.- If the request payload is invalid or the timestamp format is incorrect, the API responds with an error message.
- Status: `400 Bad Request`
- Content: JSON object containing the following keys:
- `status`: `"error"`
- `message`: `"Invalid data structure"`## How to Use
1. Install dependencies: `flask`, `pandas`, `request`
2. Run the API: To start the API server, run the following command in the terminal:
`python api-server.py`3. Once the flask app is running, following are the two end points:
- `http://127.0.0.1:5000/health - GET`
- `http://127.0.0.1:5000/getData - POST`
4. An export of postman collection is included in the project for easy set up