Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soyvural/simple-device-api
Restful API example with using go and gin framework
https://github.com/soyvural/simple-device-api
gin gin-framework go golang restful-api
Last synced: about 1 month ago
JSON representation
Restful API example with using go and gin framework
- Host: GitHub
- URL: https://github.com/soyvural/simple-device-api
- Owner: soyvural
- License: mit
- Created: 2021-11-02T14:43:48.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-18T17:59:25.000Z (about 3 years ago)
- Last Synced: 2024-06-19T16:39:07.107Z (6 months ago)
- Topics: gin, gin-framework, go, golang, restful-api
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/gin-gonic/gin) framework for http router.
### Generate OpenAPI spec doc with swagger
```shell
swag init -g doc.go
```### Build docker image locally
```shell
BUILD_VERSION=0.0.1
docker build -f build/Dockerfile -t docker.io/simple-device-api:$BUILD_VERSION .
```### Run with docker in your local
```shell
docker run -p 8080:8080 docker.io/simple-device-api:$BUILD_VERSION
```### Build and publish with docker
```shell
DOCKER_USERNAME=""
DOCKER_PASSWORD=""
sh build/build.sh $BUILD_VERSION
```### Run from source code in your local
```shell
GIN_MODE=debug go run cmd/api/main.go --port 8080
```### Swagger documentation URL
http://HOST:PORT/swagger/index.html
### Examples
#### Create a device
```shell
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
```shell
curl --location --request GET 'http://localhost:8080/api/v1/devices/{id}' \
--data-raw ''
```#### Delete a device
```shell
curl --location --request DELETE 'http://localhost:8080/api/v1/devices/{id}' \
--data-raw ''
```