https://github.com/berquerant/jsonhttp
A http server for testing.
https://github.com/berquerant/jsonhttp
go
Last synced: about 1 year ago
JSON representation
A http server for testing.
- Host: GitHub
- URL: https://github.com/berquerant/jsonhttp
- Owner: berquerant
- Created: 2021-09-09T18:46:53.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-09T18:47:14.000Z (almost 5 years ago)
- Last Synced: 2025-02-06T16:57:56.389Z (over 1 year ago)
- Topics: go
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsonhttp
A http server for testing.
# Usage
```
% jsonhttp -h
Usage of dist/jsonhttp:
-c string
config file (default "server.json")
-debug
enable debug log
-p int
port number
```
The format of `config file` is `message Server` in `pb/origin.proto`.
## Hello
```
{
"handlers": [
{
"path": "/hello",
"methodType": "GET",
"action": {
"return": {
"status": 200,
"templates": [
{
"type": "BODY",
"value": {
"m": {
"values": {
"message": {
"s": "Hello!"
}
}
}
}
}
]
}
}
}
]
}
```
## Echo with random delay
```
{
"handlers": [
{
"path": "/echo",
"methodType": "GET",
"action": {
"return": {
"status": 200,
"delay": {
"util": {
"random": {
"dice": {
"min": 200,
"max": 1000
}
}
}
}
}
}
}
]
}
```
## Proxy
```
{
"handlers": [
{
"path": "/gw",
"methodType": "GET",
"action": {
"gateway": {
"path": {
"s": "http://127.0.0.1:10000/hello"
},
"methodType": "GET",
"timeout": {
"n": 300
}
}
}
}
]
}
```
## Dynamic proxy
```
{
"handlers": [
{
"path": "/dgw",
"methodType": "POST",
"action": {
"gateway": {
"path": {
"add": {
"values": [
{
"s": "http://127.0.0.1:"
},
{
"body": {
"keys": ["port"]
}
},
{
"s": "/hello"
}
]
}
},
"methodType": "GET"
}
}
}
]
}
```
# Build
```
make build
```