a RESTful API that allows users to create, retrieve, update, and delete contact from a MongoDB database.
- Environment, Typescript, Nodemon setup
- MongoDB & Mongoose connect, Database creation
- Controllers creation
- Middlewares creation
- Token based authentication (Bearer)
- Postman testing
- Create, Read, Update Delete (CRUD) operations
- Encrypt and Decrypt phone number
- Node version 16.x
clone the Repo
git clone [email protected]:sgatana/contact-management-system.git
npm i / npm install
# or
yarn / yarn install
dir/file | description |
---|---|
src |
contains application files |
src/index.ts |
root file / app configuration |
src/config |
contains env variables and db connection |
src/controllers |
house all the controllers needed for the application |
src/helpers |
contains application files |
src/middlewares |
contains middleware needed for the application |
src/models |
contains db models and operations |
src/routes |
contains logical set of routes |
src/schemas |
contains model schemas |
API's baseURL is localhost:8080/v1
Method | path | description |
---|---|---|
POST | /auth/login |
logs in the user and generates access token |
POST | /auth/register |
register the user |
GET (Authenticated) | /contacts |
list all contacts |
POST (Authenticated) | /contacts |
create contacts |
GET (Authenticated) | /contacts/:id |
get contact by id |
PATCH (Authenticated) | /contacts/:id |
update contact |
DELETE (Authenticated) | /contacts/:id |
deletes contact |
Mongo Db connection has been initialized and mongo atlas uri has been provided in the env.ts
file found in config folder
Read more on how to create and connect to Mongo Atlas here
Run the development server using:
npm run dev
# or
yarn dev
To run the tests, run yarn test
or npm run test
- An admin user has been created to allow you interact with
protected /users routes
- Open http://localhost:8080 on your postman or API platform of your choice
- use the following admin user details to log in and generate bearer token
{
email: [email protected]
password: admin
}
-
Contacts Management endpoints (
v1/contacts
)-
contacts management endpoints are protected routes. One need to provide Bearer token in the authorization headers in order to interact with them
-
Check swagger documentation to see the required payload, path and/or query params
- POST
v1/contacts
- Creates contact - GET
v1/contacts
- Get all contacts - GET
v1/contacts/:id
- Get contact by id - PATCH
v1/contacts:/id
- Update a contact - DELETE
v1/contacts:/id
- Deletes a contact
- POST
-
-
User login endpoints (
v1/auth/login
)-
allow user to login and generate access token to be used when interacting with
contact management endpoints
.- POST
v1/auth/login
- Logs in the user and generate access token.
- POST
-
N.B check package.json
file to all packages used by the API