This project aim to build up a backend server serve the travel mobile application with RESTful APIs outlined:
- New user registration
- User account activation (Verify email address)
- User Login
- Change user password
- Forget user password
- Reset user password
- Get destination list
- Get destination covid status and information
- Get all user accounts (Development test only)
- Operation system: Windows, MacOS or Linux
- Application: Node.js version 14 https://nodejs.org/en/download/
- Database: MongoDB Community Server https://www.mongodb.com/try/download/community
- SMTP server: any accessable SMTP server e.g. Google Mail
- Visual Studio Code https://code.visualstudio.com/download
- Postman https://www.postman.com/downloads/
- Create MongoDB schema 1.1. Connect to MongoDB by client tools e.g. 'MongoDB for VS code' 1.2. Create a new Database with name 'TravelApp' 1.3. Create a Collections in 'TravelApp' Database with name 'users' 1.4. Create a Collections in 'TravelApp' Database with name 'dests' 1.5. Create a Collections in 'TravelApp' Database with name 'destinfos' Remark: The default MongoDB is installed in local and without login id and password, if you setup is different, update the proper connection string in 'server.js' file e.g. mongoose.connect('mongodb://id:pwd@host:port/TravelApp');
- git clone https://github.com/andy30sh/TravelAppServer_v2.git
- Config mailac.js 2.1. Open mailac.js file with code editor 2.2. Edit the SMTP server config, e.g. for your own Google mail account 2.3. Save the file
- npm install
- Initial database content (Optional) 4.1. Open server.js file with code editor 4.2. Change the value of 'isDbInit' to 'true' e.g. 'const isDbInit = true;' 4.3. Save the file 4.4. Execute app by run command 'npm run start' 4.5. After execute complete (message will shown in console) 4.6. Revert the value of 'isDbInit' to 'false', then save file Remark: all users with the default password as 'password123456'
- npm run start
Console message:
Travel App Server RESTful API HTTP server started on: 8088 e.g. http://localhost:8088/ Travel App Server RESTful API HTTPs server started on: 8443 e.g. https://localhost:8443/
- When you see the 'Travel App Server RESTful API server started on: 8088' message in console mean server ready for accept connection from port 8088
- Use Postman program as the RESTful client 2.1 Enter URL and select the method (GET or POST) e.g. https://localhost:8088/user/forget (POST) 2.2. Click 'Body' tag and select 'x-www-form-urlencoded' tag 2.3. Enter 'Key' and 'Value' for request parameters 2.4. Click 'Send' to submit the request 2.5. Get the response result in bottom session 2.6. Click 'Save' to store and reuse the request
- /user/create
e.g,. https://localhost:8443/user/create
- POST (x-www-form-urlencoded)
- first_name (mandatory)
- last_name (mandatory)
- email (mandatory)
- login_id (mandatory)
- password (mandatory)
-
Success
return (JSON) {login_id, login_token, last_login_date}{ "user_login": "aliceg", "login_token": "xa0SOGkvwLTblkEM", "last_login_date": null }
Fail:
return error message e.g. Activate fail!
- /user
e.g,. https://localhost:8443/user
- GET
- Nil
-
Success: return (JSON) all user objects
[ { "_id": "6170140f413337e98a2f9fe3", "first_name": "David", "last_name": "Li", "email": "[email protected]", "login_id": "davidli", "password": "d41d8cd98f00b204e9800998ecf8427e", "login_token": "Okx8eH4s0guLvyWb", "last_login_date": "2021-10-20T15:19:04.402Z", "status": [ "normal" ], "activation_token": "xxx", "created_date": "2021-10-20T13:05:19.885Z", "__v": 0 }, { "_id": "617015f91b03956cefb2b72b", "first_name": "Peter", "last_name": "Wood", "email": "[email protected]", "login_id": "peterw", "password": "cb28e00ef51374b841fb5c189b2b91c9", "login_token": "", "last_login_date": null, "status": [ "pending" ], "activation_token": "hYpDk424dXz1ktMt", "created_date": "2021-10-20T13:13:29.084Z", "__v": 0 } ]
-
Fail:
return error message
- /user/activate
e.g,. https://localhost:8443/user/activate
- POST (x-www-form-urlencoded)
- userId (mandatory)
- password (mandatory)
- activateCode (mandatory)
-
Success: return (JSON) {user_login, created_date}
{ "user_login": "aliceg", "created_date": "2021-10-20T15:46:57.739Z" }
-
Fail:
return error message e.g. duplicate login_id
- /user/login
e.g,. https://localhost:8443/user/login
- POST (x-www-form-urlencoded)
- userId (mandatory)
- password (mandatory)
-
Success:
return (JSON) {user_login, login_token, last_login_date}{ "user_login": "aliceg", "login_token": "eUy2wbB6bnVz4Zj2", "last_login_date": "2021-10-20T15:52:29.511Z" }
-
Fail:
return error message e.g. Account not active!; Login fail!
- /user/password
e.g,. https://localhost:8443/user/password
- POST (x-www-form-urlencoded)
- userId (mandatory)
- password (mandatory)
- newPassword (mandatory)
-
Success:
return (JSON) {user_login, login_token, last_login_date}{ "user_login": "aliceg", "login_token": "d8wFswRbvHnIotFe", "last_login_date": "2021-10-20T15:58:01.127Z" }
-
Fail:
return error message e.g. Incorrect login ID and email!
- /user/forget
e.g,. https://localhost:8443/user/forget
- POST (x-www-form-urlencoded)
- userId (mandatory)
- email (mandatory)
-
Success
return (JSON) {user_login, status}{ "user_login": "davidli", "status": [ "normal" ] }
-
Fail:
return error message e.g. Change password fail!
- /user/reset
e.g,. https://localhost:8443/user/reset
- POST (x-www-form-urlencoded)
- userId (mandatory)
- activateCode (mandatory)
- newPassword (mandatory)
-
Success:
return (JSON) {user_login, login_token, last_login_date}{ "user_login": "aliceg", "login_token": "6LezvjySep45s9TT", "last_login_date": "2021-10-20T16:03:35.376Z" }
-
Fail:
return error message e.g. Change password fail!
- /dest/list
e.g,. https://localhost:8443/dest/list
- POST (x-www-form-urlencoded)
- loginToken (mandatory)
-
Success:
return (JSON) {dest_code, dest_name, dest_region}[ { "dest_code": "syd", "dest_name": "Sydney", "dest_region": "NSW" }, { "dest_code": "nst", "dest_name": "Newcastle", "dest_region": "NSW" }, { "dest_code": "ade", "dest_name": "Adelaide", "dest_region": "SA" }, { "dest_code": "vch", "dest_name": "Victor Harbor", "dest_region": "SA" } ]
-
Fail:
return error message e.g. Unauthorised access!
- /dest/info
e.g,. https://localhost:8443/dest/info
- POST (x-www-form-urlencoded)
- loginToken (mandatory)
- destCode (mandatory)
-
Success:
return (JSON)[ { "_id": "617294f3e25dbbd06c580890", "dest_code": "2", "border_status": "border2", "covid_status": "covid_status2", "lockdown_status": "lockdown_status2", "covid_dashboard_link": "googel.com/covid_dashboard_link2", "Activity_restriction_link": "googel.com/Activity_restriction_link2", "travel_restriction_link": "googel.com/travel_restriction_link2", "last_update_date": "2021-10-22T10:39:47.030Z", "__v": 0 } ]
-
Fail:
return error message e.g. Unauthorised access! or Dest info not found!