An example of how to implement a Restful API on AWS by utilizing the following tech stack:
Table of Contents
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
First you need to install Go language on your system, On this website you can find installation instructions based on your system OS: https://golang.org/doc/install
Go dep will helps us manage our dependencies, you can install go-dep on your system with the following command
sudo apt-get install go-dep
Install via npm:
npm install -g serverless
- Clone the repo
git clone https://github.com/aryanbm/devices-api
- Install dependencies
dep ensure -v
- Build go files
env GOOS=linux go build -ldflags="-s -w" -o bin/getDeviceBin src/getDevice/getDevice.go
env GOOS=linux go build -ldflags="-s -w" -o bin/createDeviceBin src/createDevice/createDevice.go
or you can just use make build
- Deploy your code to AWS account
serverless deploy --verbose
or
make deploy
Test covarages are available in cover.html files
You can test getDevice
and createDevice
unit tests with the following command
go test ./src/getDevice/
go test ./src/createDevice/
or
make test
curl -X GET https://<api-gateway-url>/api/devices/id1
curl -X POST https://<api-gateway-url>/api/devices/ -H "Content-Type: application/json" --data-binary @- <<DATA
{
"id": "/devices/id1",
"deviceModel": "/devicesmodels/id1",
"name": "Sensor",
"note": "Testing a sensor.",
"serial": "A020000102"
}
DATA