Skip to content

soyvural/simple-device-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple device api

Simple Device API is really simple and concise to show how easy to implement a Restful Service with using Golang.

It uses gin framework for http router.

Generate OpenAPI spec doc with swagger

swag init -g doc.go

Build docker image locally

BUILD_VERSION=0.0.1
docker build -f build/Dockerfile -t docker.io/simple-device-api:$BUILD_VERSION .

Run with docker in your local

docker run -p 8080:8080 docker.io/simple-device-api:$BUILD_VERSION

Build and publish with docker

DOCKER_USERNAME=""
DOCKER_PASSWORD=""
sh build/build.sh $BUILD_VERSION

Run from source code in your local

GIN_MODE=debug go run cmd/api/main.go --port 8080

Swagger documentation URL

http://HOST:PORT/swagger/index.html

Examples

Create a device

curl --location --request POST 'http://127.0.0.1:8080/api/v1/devices' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name" : "Iphone",
    "brand": "Apple",
    "model": "13 Pro Max"
}'

Get a device

curl --location --request GET 'http://localhost:8080/api/v1/devices/{id}' \
--data-raw ''

Delete a device

curl --location --request DELETE 'http://localhost:8080/api/v1/devices/{id}' \
--data-raw ''

About

Restful API example with using go and gin framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published