Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.