This RESTful Web Service has several endpoints to store & retrieve locations. Implemented all the CRUD operations, used MongoDB for data persistence.
- Create a new location
POST /locations
- Retrieve a stored location
GET /locations/{location_id}
- Update an existing location
PUT /locations/{location_id}
- Delete a location
DELETE /locations/{location_id}
Note: Location ids are nothing but the ObjectId (unique identifier of type BSON generated by MongoDB)
- If you don't have it configured on your OS, check out this official manual for the step-by-step instructions to install Go.
- Install this repository/package using Go
go get github.com/onkarganjewar/CMPE273-Assignment2
- Install the httprouter package
go get github.com/julienschmidt/httprouter
- Install the MongoDB driver for Go
go get gopkg.in/mgo.v2
go get gopkg.in/mgo.v2/bson
• All the instructions for installing MongoDB can be found here.
• You will also need to create a collection, and connect to that MongoDB deployment using a standard connection URI like this:
mongodb://<dbuser>:<dbpassword>@ds012345.mongolab.com:12345/<dbname>
- Change directory to your workspace and start the server
go run tripplanner.go
-
Application will now run at http://localhost:3022/
-
Use any REST client console or POSTMAN chrome extensions to test the following endpoints:
POST /locations
{
"name" : "Bob Smith",
"address" : "123 Main St",
"city" : "San Jose",
"state" : "CA",
"zip" : "95112"
}
HTTP Response Code: 201
{
"id": "564e7f130a956e266887fc85",
"name": "Bob Smith",
"address": "123 main street",
"city": "San Jose",
"state": "CA",
"zip": "95112",
"coordinate": {
"lat": 37.128988,
"lng": -121.656946
}
}
GET /locations/564e7f130a956e266887fc85
HTTP Response Code: 200
{
"id": "564e7f130a956e266887fc85",
"name": "Bob Smith",
"address": "123 main street",
"city": "San Jose",
"state": "CA",
"zip": "95112",
"coordinate": {
"lat": 37.128988,
"lng": -121.656946
}
}
PUT /locations/564e7f130a956e266887fc85
HTTP Response Code: 202
{
"id": "564e7f130a956e266887fc85",
"name" : "John Smith",
"address" : "1600 Amphitheatre Parkway",
"city" : "Mountain View",
"state" : "CA",
"zip" : "94043",
"coordinate" : {
"lat" : 37.4220352,
"lng" : -122.0841244
}
}
DELETE /locations/564e7f130a956e266887fc85
HTTP Response Code: 200