A Simple REST API for mongoDB in GO!
Enables the mongoDB CRUD operations on any collection using simple HTTP REST calls.
This is my first serious attempt at GO programming language and mongoDB. The code works but I am sure there is a lot of room for re-factoring and clean up.
To use it in a real web app environment, the code needs to be beefed up with some authentication code around the services.
This project consists of the following three files. It has a dependency on labix.org/v2/mgo
- mongoweb.go : Main program (HTTP Server)- handles GET,POST,PUT and DELETE
- db.go : Provides wrapper methods to mGO(a native mongoDB driver in GO) CRUD fucntions
- testdb.go : Test functions for db.go
USAGE:
- GET http://localhost:8088/gomongo/services/people/6466761235764
- GET http://localhost:8088/gomongo/services/people/
- GET http://localhost:8088/gomongo/services/people?q={"name"="Jensing"}&select={"name":1,"phone":1}&limit=20&sort=-phone
- POST http://localhost:8088/gomongo/services/people/
Body: {"name":"YTRETRERETYRE","phone":"+55 53 8116 9639"} - PUT http://localhost:8088/gomongo/services/people/6466761235764
Body: {"name":"NEW NAME","phone":"+55 53 8116 9639"} - DELETE http://localhost:8088/gomongo/services/people/6466761235764
Note:
/gomongo/services is the URL that the service listens to 'people' is the name of the mongodb collections in the above examples