Dummy HTTP server generator
This project is still in WIP
Often, when developing or testing applications, you need to interact with services that provide specific responses. However, directly using these services might not be feasible due to downtime, additional costs, or other constraints.
fakery offers a solution by allowing you to effortlessly create lightweight servers with custom dummy responses for each endpoint you require. While this approach isn't groundbreaking, the inclusion of an executable or CLI makes it accessible beyond just developers, enabling quality assurance teams, among others, to utilize it effectively.
-- Pending --
To configure fakery, you simply need a JSON configuration file (e.g., config.json) with the following structure:
[
{
"request": {
"url": "/path/to/something",
"post": "this is some post data in textual format",
"headers": {
"authorization": "Basic usernamez:passwordinBase64"
},
"method": "POST"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"latency": 1000,
"body": "Your request was successfully processed!"
}
},
{
"request": {
"url": "/path/to/a/json/response",
"headers": {
"Content-Type": "application/json"
},
"method": "GET"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"message\": \"Item created\", \"item\": {\"id\": \"1\", \"name\": \"Ball\", \"price\": 9.99}}"
}
},
{
"request": {
"url": "/path/to/thing",
"headers": {
"Content-Type": "application/json"
},
"post": "this is some post data in textual format",
"method": "POST"
},
"response": {
"status": 304,
"headers": {
"Content-Type": "application/json"
}
}
}
]
Each object consists of:
- request: Request Object
- response: Response Object
Request object:
- url: string
- headers: Object with key and values as strings.
- method: string
Response object:
- status: number
- headers: Object with key and values as strings.
- body: string
- latency: number
fakery -p 42069 -d service1-data.json
To build from source:
go build
./fakery -p 42069 -d service1-data.json
The command accepts the following flags:
- p: The port where the server will run, default is port 8000.
- d: The data used by the server to create endpoints; by default, it looks for config.json.
This project is open source. Contributions are welcomed through PRs.