Example of REST API to create,retrieve,update and delete items with Go,Mysql and Revel framework
To use this sample you must have Go installed as described here, and follow the official Go code organization; MySQL installed and running, if not please check out MySQL download page and follow these instructions.
To check your installations, run the following command in the command line:
$ go version
go version go1.7.1 linux/amd64 # sample output
$ mysql --version
mysql Ver 14.14 Distrib 5.5.52, for debian-linux-gnu (x86_64) using readline 6. # sample output
This project uses Revel framework. You can install it by:
go get github.com/revel/revel
go get github.com/revel/cmd/revel
go get gopkg.in/gorp.v2
Set up MySQL database, use -u -p flags to provide username and password:
$ mysql < database_backup.sql
Once Revel framework is installed, you can run the server by:
revel run go-mysql-revel-rest
Note that the project must be located under $GOPATH/src/go-mysql-revel-rest
The API routes are defined in conf/routes
file:
GET /fruits
Retrieve all the fruits
GET /fruits/{id}
Retrieve a fruit with id {id}
POST /fruits/
Save a new fruit. name
and value
must be provided as form params.
PUT /fruits/
update a fruit with id {id}. name
and value
optional as form params.
DELETE /fruits/{id}
delete a fruit with id {id}
Language - Go
Web framework - Revel
ORM - Gorp
Database - MySQL