https://github.com/orasik/json-schema-validator-api
API example to validate POST json request against Json Schema with go lang
https://github.com/orasik/json-schema-validator-api
gin-gonic go json-schema
Last synced: about 2 months ago
JSON representation
API example to validate POST json request against Json Schema with go lang
- Host: GitHub
- URL: https://github.com/orasik/json-schema-validator-api
- Owner: orasik
- License: mit
- Created: 2017-12-21T20:07:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-22T23:00:43.000Z (over 8 years ago)
- Last Synced: 2025-09-18T14:43:53.472Z (9 months ago)
- Topics: gin-gonic, go, json-schema
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/orasik/json-schema-validator-api)
[](https://goreportcard.com/report/github.com/orasik/json-schema-validator-api)
# Data Validation API
Data validation API example to validate POST json request against Json Schema with go lang.
### Packages
- [Gin Framework](https://gin-gonic.github.io/gin/)
- [xeipuuv/gojsonschema](https://github.com/xeipuuv/gojsonschema)
- [logrus](https://github.com/sirupsen/logrus)
### How to run
#### 1) If you have golang installed:
- Clone the repo
- go get -v && go build -o api
- ./api --port 8080
Make a valid request:
```bash
curl -X POST \
http://localhost:8080/api/person \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"firstName": "Go",
"lastName": "lang"
}'
```
response would be:
```json
{
"success": true,
"errors": {}
}
```
Invalid request:
```bash
curl -X POST \
http://localhost:8080/api/person \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"noName": "Go",
"lastName": "lang"
}'
```
response:
```json
{
"success": false,
"errors": {
"firstName": "firstName is required"
}
}
```
### 2) With Docker (coming soon ...)
### Running test
```bash
go test -v
```