A simple REST API framework built using Node.js, Express and using MongoDB as a database.
Install Node and MongoDB using Homebrew
brew update
brew install node
brew install mongodb
More info on installing MongoDB can be found here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
$ git clone https://github.com/rstphnsn/node-rest-api-framework.git node-rest-api-framework
cd node-rest-api-framework
Make sure mongo is up and running
mongod
Install and start the application
npm install
npm start
The services will start running on locahost:3001.
At first run your database will be empty. You can use the services to add, update and delete documents.
To use a document name other then default "items" use the following instead of npm start
DOCUMENT_NAME=your_item_name node app.js
To run the API on a different port by use the following
PORT=3002 node app.js
If you are making changes to your own version of the framework you can use Nodemon to watch the JS files. Nodemon will then stop and restart the app when needed.
npm run dev
By default the app provides the following endpoints.
A health check endpoint to make sure the API is up and running
{
success: {
statusCode: 200,
message: "App is up and running"
}
}
Lists all documents in the items table.
[
{
"_id": "555cbad1329d9abb83621bae",
"first_name": "Stephen",
"last_name": "Dunn",
"email": "sdunn0@java.com",
"country": "China",
"lat": "28.31034",
"lng": "121.00418"
},
{
"_id": "555cbad8329d9abb83621baf",
"first_name": "Mary",
"last_name": "Owens",
"email": "mowens1@dagondesign.com",
"country": "Venezuela",
"lat": "8.81556",
"lng": "-65.3225"
},
{
"_id": "555cbae1329d9abb83621bb0",
"first_name": "Jessica",
"last_name": "Jackson",
"email": "jjackson2@utexas.edu",
"country": "Canada",
"lat": "42.91679",
"lng": "-81.41646"
}
]
Post a document into the items table.
{
"first_name": "Ann",
"last_name": "Parker",
"email": "aparker3@netlog.com",
"country": "China",
"lat": "28.37222",
"lng": "110.92722",
"_id": "555cbc27329d9abb83621bb1"
}
Get an individual document from the items table based by _id
.
{
"_id": "555cbad1329d9abb83621bae",
"first_name": "Stephen",
"last_name": "Dunn",
"email": "sdunn0@java.com",
"country": "China",
"lat": "28.31034",
"lng": "121.00418"
}
Update an individual document from the items table based by _id
. This is currently set up so that you do not need to put the whole object. Individual properties can be updated. If a property is PUT that doesn't exist on the document it will be added to the document.
{
"_id": "555cbad1329d9abb83621bae",
"first_name": "Stephen",
"last_name": "Dunn",
"email": "sdunn0@java.com",
"country": "China",
"lat": "28.31034",
"lng": "121.00418"
}
Delete an individual document from the items table based by _id
.
{}