A Hapi boilerplate restful api server using ECMAScript 7
"hapi-async-methods" (Written by me, to import methods from package with async style)
"hapi-async-routes" (Written by me, to import route handlers from package with async style)
"hapi-jwt-token" (Written by me, combine with hapi-auth-jwt2 for easier access token validation)
"hapi-mongoose-bluebird" (Written by me, connect to mongo and get the bluebird promise, enable accessibility to models from server)
All of the above are MIT licences, you can use them in you own project.
"crumb" (Protect csrf, currently disabled because of test cases)
"good" (Hapi official plugin for logger)
"good-winston-reporter" (Winston reporter for good)
"hapi-auth-jwt2" (Enable user validation by access token (jsonwebtoken))
"hapi-authorization" (Enable role based acl)
"joi"
"babel"
"babel-preset-es2015-node5" (To make sure babel would not mistakenly transform generater that node5 already support)
"babel-preset-stage-0" (To enable async, await)
"babel-register" (Require hook for backend)
"lab"
"code"
"eslint"
"babel-eslint" (Parser for eslint using babel as transformer)
"import-directory" (Same as require-directory but take module.default (ES6 export default syntax) to concern)
redis (Turn it on on localhost with port 6347, it is used fo catbox-redis to cache the user access token)
mongodb (Turn it on localhost with port 27017, it is used to store User)
- git clone
- npm install
- install mongo and redis, start both of them. (See Database section)
- npm run test, make sure all test cases passed.
- insert an admin User to mongodb, collection: User
{
email: '[email protected]',
username: 'admin',
password: 'admin1234',
role: 'ADMIN'
} - start server by node ./server.js
- open postman or other tools to test API List
POST http://localhost:8080/login , {email: ..., password: ...}, return {access-token: ....}
(Please copy the access-token for later use, I have not enable set-cookie, you need to put the access-token to header: authorization for every later api)
GET http://localhost:8080/users, return whole list of user
POST http://localhost:8080/users, {email: ..., password: ..., role: ..., username: ...}, return created user
GET http://localhost:8080/users/{userId}, return user
PUT http://localhost:8080/users/{userId}, (limited to ADMIN role if update other user) {email: ..., password: ..., role: ..., username: ...}, return updated user
DELETE http://localhost:8080/users/{userId}, (limited to ADMIN role) return deleted user
GET/POST http://localhost:8080/logout