Skip to content

Latest commit

 

History

History
200 lines (142 loc) · 3.52 KB

README.md

File metadata and controls

200 lines (142 loc) · 3.52 KB

RESTful Location & Trip planner Service in Golang

This RESTful Web Service has several endpoints to store & retrieve locations. Implemented all the CRUD operations, used MongoDB for data persistence.

Features

  • 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)   

Requirements

Installation

Installing Go

  • If you don't have it configured on your OS, check out this official manual for the step-by-step instructions to install Go.

Installing Packages

  1. Install this repository/package using Go
go get github.com/onkarganjewar/CMPE273-Assignment2
  1. Install the httprouter package
go get github.com/julienschmidt/httprouter
  1. Install the MongoDB driver for Go
go get gopkg.in/mgo.v2
go get gopkg.in/mgo.v2/bson

Deploying MongoDB

• 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>

Demo

  • Change directory to your workspace and start the server
go run tripplanner.go

POST - Create a new location

Request

POST /locations
{
   "name" : "Bob Smith",
   "address" : "123 Main St",
   "city" : "San Jose",
   "state" : "CA",
   "zip" : "95112"
}

Response

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 - Retrieve a stored location

Request

GET /locations/564e7f130a956e266887fc85

Response

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 - Update an existing location

Request

PUT /locations/564e7f130a956e266887fc85

Response

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 - Delete a location

Request

DELETE /locations/564e7f130a956e266887fc85

Response

HTTP Response Code: 200