Jessica Wicksnin

Web and Tech Enthusiast in Seattle



RESTful API – Hold on to your mongeese!

Requirements:  Node with express and mongoose installed.  MondoDB installed globally.  A lot of patience.

First, make sure you can start your mongo database with commands like mongod and mongo.  You can interact with the database directly from the command line.  Or try this website that is a mongoose playground.  http://try.mongodb.org/

Next, set up your root directory, complete with node modules and package.json files.

Then, set up the node server to work with the mongodb using mongoose.

You will need some schemas that dictate what types of data are going into your json objects.

Create functions for POST, PUT, GET, DELETE.

Use jquery in the console to try out your CRUD system.

You can always check out your database via command line: db.<yourdb>.find()[0]; can find and prettify the first item in your database, for example.

See this tutorial http://pixelhandler.com/blog/2012/02/09/develop-a-restful-api-using-node-js-with-express-and-mongoose/ for a nice, more complex than a todo list, example.  You will have to fill in some blanks for yourself: check out the mongoose documentation.

In order to hook up your api to an actual web site/app with an interface, just connect your site to the api (will be doing in an upcoming post).

Please see and fork and clone my example repo: https://github.com/jwicksnin/restful_tutorial