A REST API server implementation built on top Node.js and Express.js with Mongoose.js for MongoDB (MLAB) integration. Access control for selected Routes using Passport.js.
Details The Server provides access to CRUD operations for database of Developers assigned to Categories
You need to have NodeJs installed on your machine. The Server was written on Nodejs v8.11.4
- Yarn
- Setup Database in your Env file
- Make Env file - example gist
- npm start -- Port 3000 by default
- npm test
-
URL /contact Methods
-
GET All Contacts (Returns a List/Array) - Open Access without Token
Response [ { "_id": "5c0fbd14f7d2f0361df73507", "firstname": "Samnuel", "lastname": "Victor", "email": "vtest@email.com", "phone": 8062239670, "category": { "_id": "5c07bed0a55cd01aecbc70f8", "name": "Full Stack" }, "createdAt": "2018-12-11T13:35:16.160Z", "updatedAt": "2018-12-17T14:48:04.837Z" } ]
-
POST (Add a new Contact) - Secured Header = "x-auth-token" : "token from login"
Body
{ "category": "category_id from an already created category", "firstname": "usrfirstname", "lastname": "usrlastname", "email": "test@email.com"", "phone": 87677766 }
-
PUT (Update created contact) - Secured
Header = "x-auth-token" : "token from login" Body
{ "id": "contact id" "category": "category_id from an already created category", "firstname": "usrfirstname", "lastname": "usrlastname", "email": "test@email.com"", "phone": 87677766 }
-
DELETE (Remove and exist Contact) - Secured Header = "x-auth-token" : "token from login" Body
{ "id": "contact id" }
-
-
URL /contact/contactId - Secured Method = GET
Header = "x-auth-token" : "token from login"
-
URL /categories Methods
-
GET All Categories (Returns a List/Array) - Open Access without Token
Response [ { "_id": "5c07bed0a55cd01aecbc70f8", "name": "Full Stack" } ]
-
POST (Add a new Category) - Secured Header = "x-auth-token" : "token from login"
Body {"name" : "Category name"}
-
PUT (Update created contact) - Secured Header = "x-auth-token" : "token from login"
Body {"id": "category id", "name" : "Category name"}
-
DELETE (Remove and exist Contact) - Secured Header = "x-auth-token" : "token from login"
Body {"id": "category id"}
-
-
URL /category/categoryId - Secured
Method = GET - Get a single result
-
URL /auth/register
Params { "email" : "test@email.com", "password" : "password@1", "firstname": "usrfirstname", "lastname" : "usrlastname" }
Success Response { "message": "User registered", "data": { "email": "test@email.com", "firstname": "usrfirstname", "lastname": "usrlastname", "_id": "5c214edbbbb919542273221e", "createdAt": "2018-12-24T21:25:47.794Z" } }
Error Response { "message": "User with email (test@email.com) already exists" }
-
URL /auth/login
Params { "email" : "test@email.com", "password" : "password@1" }
Success Response {"token": "token value"}
Error Response { "message": { "errors": { "email or password": "is invalid" } } }