This simple API handle a list of Gophers. It alllows to:
- list the existing Gophers
- display the information about a Gopher
- create a new Gopher
- delete a Gopher
- update the path and the URL of a Gopher
Gophers API is available in Docker Hub.
docker run -p 8080:8080 scraly/gophers-api:linux-amd64
Install Go in 1.16 version minimum.
Install Taskfile (optional):
brew install go-task/tap/go-task
Install go-swagger:
brew tap go-swagger/go-swagger
brew install go-swagger
swagger version
go build -o bin/gophers-api internal/main.go
// or
task build
go run internal/main.go
// or
task run
This will open you browser on Swagger UI
task swagger.serve
- Get all Gophers:
curl localhost:8080/gophers
Response:
[{"displayname":"5th Element","name":"5th-element","url":"https://raw.githubusercontent.com/scraly/gophers/main/5th-element.png"}]
- Get a Gopher with the input name
curl "localhost:8080/gopher?name=5th-element"
Response:
{"displayname":"5th Element","name":"5th-element","url":"https://raw.githubusercontent.com/scraly/gophers/main/5th-element.png"}
/!\ Returns a 404 HTTP Error Code if a Gopher have not been found for the given name.
- Add a new Gopher
curl -X POST localhost:8080/gopher \
-H "Content-Type: application/json" \
-d '{"name":"yoda-gopher","displayname":"Yoda Gopher","url":"https://raw.githubusercontent.com/scraly/gophers/main/yoda-gopher.png"}'
Response:
{"displayname":"Yoda Gopher.png","name":"yoda-gopher","url":"https://raw.githubusercontent.com/scraly/gophers/main/yoda-gopher.png"}
Add another Gopher:
curl -X POST localhost:8080/gopher \
-H "Content-Type: application/json" \
-d '{"name":"jurassic-park","displayname":"Gopher Park","url":"https://raw.githubusercontent.com/scraly/gophers/main/jurassic-park.png"}'
- Delete a Gopher
curl -X DELETE "localhost:8080/gopher?name=5th-element"
- Update a Gopher
curl -X PUT localhost:8080/gopher \
-H "Content-Type: application/json" \
-d '{"name":"yoda-gopher","displayname":"El mejor Yoda Gopher","url":"https://raw.githubusercontent.com/scraly/gophers/main/yoda-gopher.png"}'
Response:
{"displayname":"El mejor Yoda Gopher","name":"yoda-gopher","url":"https://raw.githubusercontent.com/scraly/gophers/main/yoda-gopher.png"}
- Build a docker image for our current/host platform:
DOCKER_BUILDKIT=1 docker build -t gophers-api .
- Build for GitPod (linux/amd64) and push to the Docker Hub:
docker buildx build --platform linux/amd64 -t scraly/gophers-api:linux-amd64 . --push
Install the CLI:
brew install goreleaser
Generate .goreleaser.yml (the firt time):
goreleaser init
Release:
goreleaser release --snapshot --skip-publish --rm-dist
This API use go-swagger