Simple example of an api using golang-standards/project-layout as the project structure, it uses a wrapper of gin-gonic/gin as its HTTP web framework and mysql database for storage.
This example is based on joaquinlpereyra's go projects, most of the /pkg folder wrapper are his owns, so thanks for such a nice work joaquito!
Get the project
go get pclavier92/go-restful-api
Create the database
mysql -u root -p < scripts/db_schema.sql
Run the API!
go run cmd/music/main.go
localhost:3000/songs
localhost:3000/songs/<name>
localhost:3000/songs/<name>
Body raw(application/json)
{
"name": "<name>",
"duration": "mm:ss",
"artistId": 1
}
localhost:3000/songs/<name>
Body raw(application/json)
{
"name": "<name>",
"duration": "mm:ss",
"artistId": 1
}
localhost:3000/songs/<name>
localhost:3000/artists
localhost:3000/artists/<name>
localhost:3000/artists/<name>
Body raw(application/json)
{
"name": "<name>"
}
localhost:3000/artists/<name>