https://github.com/abiosoft/caddy-json-parse
Caddy v2 module for parsing json request
https://github.com/abiosoft/caddy-json-parse
caddy caddy-module caddyserver json json-parser
Last synced: 2 months ago
JSON representation
Caddy v2 module for parsing json request
- Host: GitHub
- URL: https://github.com/abiosoft/caddy-json-parse
- Owner: abiosoft
- License: apache-2.0
- Created: 2020-05-13T20:05:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-22T20:54:24.000Z (about 4 years ago)
- Last Synced: 2025-03-18T06:51:35.861Z (2 months ago)
- Topics: caddy, caddy-module, caddyserver, json, json-parser
- Language: Go
- Homepage:
- Size: 81.1 KB
- Stars: 18
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/abiosoft/caddy-json-parse/actions)
# caddy-json-parse
Caddy v2 module for parsing json request body.## Installation
```
xcaddy build v2.0.0 \
--with github.com/abiosoft/caddy-json-parse
```## Usage
`json_parse` parses the request body as json for reference as [placeholders](https://caddyserver.com/docs/caddyfile/concepts#placeholders).
### Caddyfile
Simply use the directive anywhere in a route. If set, `strict` responds with bad request if the request body is an invalid json.
```
json_parse []
```And reference variables via `{json.*}` placeholders. Where `*` can get as deep as possible. e.g. `{json.items.0.label}`
#### Example
Run a [command](https://github.com/abiosoft/caddy-exec) only if the github webhook is a push on master branch.
```
@webhook {
expression {json.ref}.endsWith('/master')
}
route {
json_parse # enable json parser
exec @webhook git pull origin master
}
```### JSON
`json_parse` can be part of any route as an handler
```jsonc
{
...
"routes": [
{
"handle": [
{
"handler": "json_parse",// if set to true, returns bad request for invalid json
"strict": false
},
...
]
},
...
]
}
```## License
Apache 2