Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/januschung/mock
https://github.com/januschung/mock
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/januschung/mock
- Owner: januschung
- License: gpl-2.0
- Created: 2023-01-01T20:24:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-05T07:29:46.000Z (10 months ago)
- Last Synced: 2024-03-05T08:40:45.104Z (10 months ago)
- Language: Java
- Size: 36.1 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#### Introduction
This is a simple REST mock server written with Java Spring Boot 3.2.3 and Java 17.
It provides sample endpoints to render output either based on static resource file or simple logic as defined in the service classes.
The server can either be brought up as a standalone jar application or as a docker.
Feel free to provide feedback or feature request.
#### Customize the Mock Service
I tried to keep it simple with the controller and service class implementation so that one can easily modify the endpoint name, parameter, service logic as well
as the return response from the static file.#### Available Endpoints:
/resource?data=[value]
This mock service returns static response from the file located in `src/main/resources/data`
_Sample 1_
**curl "http://localhost:9090/resource?data=100"**
will return
```console
[
{"id":"100","name":"jack","age":"30"},
{"id":"101","name":"jill","age":"32"}
]
```_Sample 2_
**curl "http://localhost:9090/resource?data=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:9090/resource?data=300"**
will return
```console
[]
```/status?code=[value]
_Sample 1_
**curl "http://localhost:9090/status?code=200"**
will return status code 200 and the following response
```console
200 OK
```_Sample 2_
**curl "http://localhost:9090/status?code=400"**
will return status code 400 and the following response
```console
400 BAD_REQUEST
```/delay?code=[value]
_Sample 1_
**curl "http://localhost:9090/delay?ms=3000"**
will return response with 3000 milliseconds delay
```console
Response with delay of 3000 milliseconds
```#### Swagger API Documentation
Swagger is setup and available via the following endpoint for quick reference and testing of the mock service:
`http://localhost:9090/swagger-ui/index.html`
#### Build and run
```console
mvn clean install
java -jar target/tnite-mock-1.0-SNAPSHOT.jar
```
#### Build and run with docker
```console
mvn clean install && docker build -t tnite-mock:latest .
docker run -p 9090:9090 tnite-mock:latest
```