You need git to clone the Book Sharing Backend repository. You can get git from http://git-scm.com/.
You also must have node.js and its package manager (npm) installed. You can get them from http://nodejs.org/.
Clone the Book-Sharing-Backend using Git
https://github.com/vanhtuan0409/Book-Sharing-Backend.git
cd Book-Sharing-Backend
Run this command to install dependencies using node.js tool npm
npm install
Run this command to start the server
sails start
This directory layout is based on SailsJS framework. For more information please visit http://sailsjs.org/documentation/
api/ <--- all source file location
controllers/ <--- controllers location
models/ <--- app data models location
policies/ <--- custom security policies implement
responses/ <--- custom http response
services/ <--- app custom service such as Array Manipulation, Email sending
config/ <--- sails config files, visit sails document for more detail
All of the models consists of pre-defined API from sailsJS blueprint which include:
- find
- findOne
- create
- update
- destroy
- populate
- add
- remove
For more details on blueprint api please visit http://sailsjs.org/documentation/reference/blueprint-api
Important: all blueprint api started with /api
in the URL. For example: the find Book Model will have URL as /api/book/:id
- Url:
/api/auth
- Method:
GET
- Response:
- Success:
{ error: false, content: 'User Model' }
- Error:
{ error: true, content: 'error message' }
- Url:
/api/auth
- Method:
POST
- Data:
{
token: ...
}
- Response:
- Success:
{ error: false, content: 'User Model' }
- Error:
{ error: true, content: 'error message' }
- Url:
/api/auth/logout
- Method:
GET
- Response:
{
error: false,
content: 'Logged out'
}
- Url:
api/user/:userId/borrow
- Method:
POST
- Data:
{
requestToUser: ...,
bookId: ...,
startDate: ..., (optional)
returnDate: ..., (optional)
message: ... (optional)
}
- Response:
- Success:
{ error: false, content: 'Borrow Model' }
- Error:
{ error: true, content: 'error message' }
- Url:
api/user/:userId/addBook
, - Method:
POST
, - Data:
{
bookname: ...,
author: ...,
url: ...,
description: ...,
type: ...,
isBook: true/false
}
- Response:
- Success:
{ error: false, content: 'User Model' }
- Error:
{ error: true, content: 'error message' }