Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/januschung/mock-flask
A simple mock server create with Python Flask
https://github.com/januschung/mock-flask
blueprint docker docker-compose flask gunicorn mock mock-server python restful-api
Last synced: 6 days ago
JSON representation
A simple mock server create with Python Flask
- Host: GitHub
- URL: https://github.com/januschung/mock-flask
- Owner: januschung
- Created: 2023-06-19T22:12:16.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-03T06:06:44.000Z (10 months ago)
- Last Synced: 2024-03-04T06:22:14.820Z (10 months ago)
- Topics: blueprint, docker, docker-compose, flask, gunicorn, mock, mock-server, python, restful-api
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### Introduction
This is a simple REST mock server written with Python `3.12` and Flask `3.0.2`. It also comes with Gunicorn which enables hot reload for local development.
It provides sample endpoints to render output either based on static resource file or simple logic as defined in `mock.py`.
The server can either be brought up as a standalone python application or as a docker.
Feel free to provide feedback or feature request.
#### Customize the Mock Service
For the resouce endpoint, You can modify the return value by adding a new file or editing the file under `static` folder.
#### Available Endpoints:
/resource/[value]
This mock service returns static response from the file located in `src/main/resources/data`
_Sample 1_
**curl "http://localhost:5000/resource/100"**
will return
```console
[
{"id":"100","name":"jack","age":"30"},
{"id":"101","name":"jill","age":"32"}
]
```_Sample 2_
**curl "http://localhost:5000/resource/200"**
will return
```console
[
{"id":"200","name":"tom","age":"40"},
{"id":"201","name":"jerry","age":"28"}
]
```When request with a non existing file, the response will be reading from file `empty`
_Sample 3_
**curl "http://localhost:5000/resource/300"**
will return
```console
[]
```/http_status/[value]
_Sample 1_
**curl "http://localhost:5000/http_status/200"**
will return status code 200 and the following response
```console
200 OK
```_Sample 2_
**curl "http://localhost:5000/http_status/400"**
will return status code 400 and the following response
```console
400 BAD_REQUEST
```/delay/[value]
_Sample 1_
**curl "http://localhost:5000/delay/3000"**
will return response with 3000 milliseconds delay
```console
Response with delay of 3000 milliseconds
```#### Build and run
```console
cd app
gunicorn --reload --bind localhost:3000 "app:app"
```#### Build and run with docker
```console
cd app
docker build -t mock-flask .
docker run -p 9000:80 mock-flask
```#### Build and run with docker-compose
```console
docker-compose up -d
```## Contributing
I appreciate all suggestions or PRs which will help making the mock better. Feel free to fork the project and create a pull request with your idea.