Skip to content

API example to validate POST json request against Json Schema with go lang

License

Notifications You must be signed in to change notification settings

orasik/json-schema-validator-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Go Report Card

Data Validation API

Data validation API example to validate POST json request against Json Schema with go lang.

Packages

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:

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:

{
    "success": true,
    "errors": {}
}

Invalid request:

curl -X POST \
  http://localhost:8080/api/person \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"noName": "Go",
	"lastName": "lang"
}'

response:

{
    "success": false,
    "errors": {
        "firstName": "firstName is required"
    }
}

2) With Docker (coming soon ...)

Running test

go test -v

About

API example to validate POST json request against Json Schema with go lang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages