Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shikha-code36/flask-rediscaching-in-docker
Flask Api with Redis caching in docker
https://github.com/shikha-code36/flask-rediscaching-in-docker
docker docker-compose docker-container docker-image dockerfile flask flask-api flask-caching flask-restful flask-sqlalchemy python python3 redis redis-cache rest-api
Last synced: 2 days ago
JSON representation
Flask Api with Redis caching in docker
- Host: GitHub
- URL: https://github.com/shikha-code36/flask-rediscaching-in-docker
- Owner: Shikha-code36
- License: mit
- Created: 2022-07-23T11:19:48.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-18T17:52:31.000Z (almost 2 years ago)
- Last Synced: 2025-01-13T15:17:26.688Z (2 days ago)
- Topics: docker, docker-compose, docker-container, docker-image, dockerfile, flask, flask-api, flask-caching, flask-restful, flask-sqlalchemy, python, python3, redis, redis-cache, rest-api
- Language: Python
- Homepage:
- Size: 153 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask API with Redis Caching in Docker
This is a simple Flask API project that uses Redis caching and can be run in a Docker container. The API has the following endpoints:
- `/getdata/`: Returns the latest information for a given device ID, including device_fk_id, latitude, longitude, time_stamp, sts, and speed.
- `/getlocation/`: Returns the start location and end location for a given device ID as a tuple of (latitude, longitude).
- `/getinfo`: Takes in device ID, start time, and end time and returns all the location points as a list of latitude, longitude, and time stamp.## Usage
1. Clone the repository: `git clone https://github.com//Flask-RedisCaching-in-Docker.git`
2. Navigate to the project directory in your terminal.
3. Build the Docker image: `docker build -t flask-api-with-caching`.
4. Start the Docker containers: `docker-compose`.
5. Access the API endpoints at `http://127.0.0.1:5000/`- **Note** Replace `` with your GitHub username in step 1.
### Endpoints
#### /allData
Returns the latest information for all device ID, including device_fk_id, latitude, longitude, time_stamp, sts, and speed.
**Request URL:** `http://127.0.0.1:5000/alldata`
**Request Method:** GET
**URL Params:**
- None
**Response:**
```
[{
"device_fk_id": "",
"latitude": "",
"longitude": "",
"time_stamp": "",
"sts": "",
"speed": ""
},
{
"device_fk_id": "",
"latitude": "",
"longitude": "",
"time_stamp": "",
"sts": "",
"speed": ""
}
...
]
```#### /getdata/
Returns the latest information for a given device ID, including device_fk_id, latitude, longitude, time_stamp, sts, and speed.
**Request URL:** `http://127.0.0.1:5000/getdata/`
**Request Method:** GET
**URL Params:**
- `device_fk_id` (required): The device ID for which you want to retrieve information.
**Response:**
```
{
"device_fk_id": "",
"latitude": "",
"longitude": "",
"time_stamp": "",
"sts": "",
"speed": ""
}
```#### /getlocation/
Returns the start location and end location for a given device ID as a tuple of (latitude, longitude).
**Request URL:** `http://127.0.0.1:5000/getlocation/`
**Request Method:** GET
**URL Params:**
- `device_fk_id` (required): The device ID for which you want to retrieve location information.
**Response:**
```
{
"start_location": [
"",
""
],
"end_location": [
"",
""
]
}
```#### /getinfo
Takes in device ID, start time, and end time and returns all the location points as a list of latitude, longitude, and time stamp.
**Request URL:** `http://127.0.0.1:5000/getinfo`
**Request Method:** GET
**URL Params:**
- `deviceId` (required): The device ID for which you want to retrieve location information.
- `starttime` (optional): The start time for the location points (format: %Y-%m-%dT%H:%M:%SZ).
- `endtime` (optional): The end time for the location points (format: %Y-%m-%dT%H:%M:%SZ).**Response:**
```
[
{
"latitude": "",
"longitude": "",
"time_stamp": ""
},
{
"latitude": "",
"longitude": "",
"time_stamp": ""
},
...
]
```## Dependencies
- Flask
- Flask-Caching
- Redis
- SQLAlchemy## Files
```
Flask-RedisCaching-in-Docker
├── app/
│ ├── init.py
│ ├── getData.py
│ ├── getInfo.py
│ ├── location.py
│ └── allData.py
├── utils/
│ └── raw_data.csv
├── .gitignore
├── data.py
├── constant.py
├── Dockerfile
├── docker-compose.yml
└── model.py
```- `app/`: Contains the Flask application code.
- `__init__.py`: Initializes the Flask app and registers the routes.
- `getData.py`: Contains the code for the `/getdata/` endpoint.
- `getInfo.py`: Contains the code for the `/getinfo` endpoint.
- `location.py`: Contains the code for the `/getlocation/` endpoint.
- `allData.py`: Contains the code for the `/alldata` endpoint.
- `utils/`: Contains the raw data in `raw_data.csv` file.
- `.gitignore`: Specifies files that should be ignored by Git.
- `data.py`: Contains functions for retrieving data.
- `constant.py`: Contains constant values used throughout the application.
- `Dockerfile`: Contains instructions for building the Docker image.
- `docker-compose.yml`: Contains instructions for running the Docker container.
- `model.py`: Contains the data model for the application.## Caching
The application uses Redis as the caching layer, with a caching timeout of 120 seconds.