NodeGrid is a simple, light-weight backend as a service framework for mobile applications. Build you app, we care about your backend. NodeGrid core is built top of light-weight NodeJS and MongoDB
NodeGrid contains REST API for provide the services. NodeGrid provide following services
- User Management
- Enable Security
- Store and Query dynamic entities (CRUD operations)
- Create relations between dynamic entities
- Send push notification
- Enable server side events
Developers now need to worry about their application's backend users. NodeGrid provide service for users operations and developers can keep there dynamic data in user object as they wish
In each API requests are authenticated using token authentication. For using the NodeGrid, user need to log-in and get a token from system to access the other REST calls.
Authenticated user can create, read, update, delete entities just using simple REST calls
This is one of special feature NodeGrid provide to developers. Developers can create relations between the objects and entities they created dynamically. This also can do from simple REST call.
- Node server - v0.10.0 or higher (http://nodejs.org/)
- NodeJS dependency installer
npm(https://www.npmjs.org/) - MongoDB server - v2.6 or higher (http://www.mongodb.org/)
After setup the pre-requisite clone the NodeGrid to your system.
-
Install nodejs dependencies,
npm install
-
Run the NodeGrid,
node app.js
After you install and start NodeGrid you can check the application status
URL: http://localhost:3000/system/status
Request Type: GET
curl -X GET -H "Content-Type: application/json" http://localhost:3000/system/status
Sample Response:
{
"status": "SUCCESS",
"mongo-connection": "CONNECTED"
}
To use NodeGrid you need to create users, Those users can access the REST API.
URL: http://localhost:3000/system/user
Request Type: POST
Data Object: {"name":"John Smith", "username":"john", "password":"john123"}
curl -X POST -H "Content-Type: application/json" -d '{"name":"John Smith", "username":"john", "password":"john123"}' http://localhost:3000/system/user
Sample Response:
{
"status": "SUCCESS",
"msg": "New system user added successfully",
"data": {
"__v": 0,
"data": {
"lastAccessedTime": "",
"createdTime": 1416892013,
"password": "$2a$10$pUu03u5k260tuIKaJpM1cODK0D2CsTj.GxzFHMBfwrHLRHmCOn5/u",
"username": "john",
"name": "John Smith"
},
"_id": "54740e6d721de8b8135dfb4e"
}
}
Replace the <userId> from your user's id.
URL: http://localhost:3000/system/user/<userId>
Request Type: GET
curl -X GET -H "Content-Type: application/json" http://localhost:3000/system/user/\<userId>
Sample Response:
{
"status": "SUCCESS",
"msg": "Data retrieved successfully",
"data": [
{
"_id": "54740e6d721de8b8135dfb4e",
"data": {
"name": "John Smith",
"username": "john",
"password": "$2a$10$pUu03u5k260tuIKaJpM1cODK0D2CsTj.GxzFHMBfwrHLRHmCOn5/u",
"createdTime": 1416892013,
"lastAccessedTime": ""
},
"__v": 0
}
]
}
Replace the <username> from your user's username.
URL: http://localhost:3000/system/user/<username>
Request Type: GET
curl -X GET -H "Content-Type: application/json" http://localhost:3000/system/user/\<username>
Sample Response:
{
"status": "SUCCESS",
"msg": "Data retrieved successfully",
"data": [
{
"_id": "54740e6d721de8b8135dfb4e",
"data": {
"name": "John Smith",
"username": "john",
"password": "$2a$10$pUu03u5k260tuIKaJpM1cODK0D2CsTj.GxzFHMBfwrHLRHmCOn5/u",
"createdTime": 1416892013,
"lastAccessedTime": ""
},
"__v": 0
}
]
}
Replace the <userId> from your user's id.
URL: http://localhost:3000/system/user/<userId>
Request Type: DELETE
curl -X DELETE -H "Content-Type: application/json" http://localhost:3000/system/user/\<userId>
Sample Response:
{
"status": "SUCCESS",
"msg": "System user removed from the collection successfully.",
"data": 1
}
Created user need to authenticate NodeGrid to access the REST API. This authentication happen from accessToken. For each and every REST call, user need to pass accessToken.
URL: http://localhost:3000/system/security/generateToken
Request Type: POST
Data Object: {"username":"john", "password":"john123"}
curl -X POST -H "Content-Type: application/json" -d '{"username":"john", "password":"john123"}' http://localhost:3000/system/security/generateToken
Sample Response:
{
"status": "SUCCESS",
"msg": "New accessToken saved successfully",
"data": {
"__v": 0,
"data": {
"status": "valid",
"expiringTime": 1416980339,
"createdTime": 1416893939,
"userId": "547415c57cb17d271ce44ae7",
"accessToken": "f02a2e0e569b8fc216b3d1da6035d6581ea1cec4"
},
"_id": "547415f37cb17d271ce44ae8"
}
}
Users can create dynmic entities and do CRUD operations from NodeGrid.
As an example let's get entity called books. In books entity has follwing type object {"name":"NodeGrid Tutorials", "author":"John Smith", "type": "Tutorials"}.
This request is authenticated from user accessToken. Therefore you need to set Authorization HEADER to request.
Replace the <accessToken> from your user's accessToken.
URL: http://localhost:3000/app/books
Request Type: POST
Data Object: {"name":"NodeGrid Tutorials", "author":"John Smith"}
curl -X POST -H "Content-Type: application/json" -H "Authorization: <accessToken>" -d '{"name":"NodeGrid Tutorials", "Author":"John Smith", "type": "Tutorials"}' http://localhost:3000/app/books
Sample Response:
{
"status": "SUCCESS",
"msg": "New model added successfully",
"data": {
"__v": 0,
"data": {
"type": "Tutorials",
"Author": "John Smith",
"name": "NodeGrid Tutorials"
},
"_id": "54759bfb14706eb4488f9b7c"
}
}
Let's use the same example entity books.
This request is authenticated from user accessToken. Therefore you need to set Authorization HEADER to request.
Replace the <accessToken> from your user's accessToken.
URL: http://localhost:3000/app/books
Request Type: GET
curl -X GET -H "Content-Type: application/json" -H "Authorization: <accessToken>" http://localhost:3000/app/books
Sample Response:
{
"status": "SUCCESS",
"msg": "[books] data successfully retrieved",
"data": [
{
"_id": "5451bb4e3ab7a4760fed4fea",
"data": {
"type": "Story",
"author": "J. R. R. Tolkien",
"name": "The Hobbit"
},
"__v": 0
},
{
"_id": "54759bfb14706eb4488f9b7c",
"data": {
"type": "Tutorials",
"name": "NodeGrid Tutorials",
"Author": "John Smith"
},
"__v": 0
}
]
}
Let's use the same example entity books.
This request is authenticated from user accessToken. Therefore you need to set Authorization HEADER to request.
Replace the <accessToken> from your user's accessToken.
Replace the <object id> from your entity object id
URL: http://localhost:3000/app/books/<object id>
Request Type: GET
curl -X GET -H "Content-Type: application/json" -H "Authorization: <accessToken>" http://localhost:3000/app/books/\<object id>
Sample Response:
{
"status": "SUCCESS",
"msg": "[books] data successfully retrieved",
"data": [
{
"_id": "54759bfb14706eb4488f9b7c",
"data": {
"type": "Tutorials",
"name": "NodeGrid Tutorials",
"Author": "John Smith"
},
"__v": 0
}
]
}
Let's use the same example entity books.
This request is authenticated from user accessToken. Therefore you need to set Authorization HEADER to request.
Replace the <accessToken> from your user's accessToken.
Replace the <object id> from your entity object id
URL: http://localhost:3000/app/books/<object id>
Request Type: DELETE
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: <accessToken>" http://localhost:3000/app/books/\<object id>
Sample Response:
{
"status": "SUCCESS",
"msg": "[books] data successfully deleted",
"data": {
"_id": "54759bfb14706eb4488f9b7c",
"data": {
"type": "Tutorials",
"name": "NodeGrid Tutorials",
"Author": "John Smith"
},
"__v": 0
}
}