SMS Application is an API that allows for the sending and receiving of messages. It is built using NodeJS, express, mongodb and typescript.
In order to run this project locally you would need to have:
- Node (Best to install v10.4.0). You can use NVM to install and manage node versions on your machine
- MongoDB (For this project I used a docker image of mongoDB.)
- Docker (if you plan to setup mongoDB to run in a docker image)
- Yarn - After installing node install Yarn globally by running
npm -g install yarn
You can run a docker image of mongo DB using docker run -p 27017:27017 mongo:3.4.20-jessie
This command will download the specified mongo image if it does not exist locally and run the image. For this case am running the image mongo:3.4.20-jessie
but you can get a list of mongo images here. The -p 27017:27017
specifies that the running image is being exposed on port 27017
- Clone the repository
git clone https://github.com/malmike/SMSApplication.git
- Enter the directory and install the project dependencies
cd SMSApplication yarn install
- Rename sample.env to .env
mv sample.env .env
- Start mongodb service.
- If you install mongodb locally run
If you require authentication
mongod
sudo mongod
- If you setup mongodb to run in docker then just ensure that the image is running
If the image is not running then run the command
docker container ls
docker run -p 27017:27017 mongo:3.4.20-jessie
DB_URI=mongodb://localhost:27017/smsapplication
- If you install mongodb locally run
- Starting the application
The development environment is setup to allow live reloading using nodemon
yarn start-dev
- You can access the application in the browser
The API uses swagger for documentation and this can be accessed at
http://localhost:1337
http://localhost:1337/api-docs/
To execute the applications tests run
yarn test
To execute tests with coverage run
yarn test-coverage
TYPE | API ENDPOINT | DESCRIPTION | HEADERS | PAYLOAD |
---|---|---|---|---|
POST | /registerUser | Creates a user or signs in a existing user | content-type: applicaton/json |
{ "name": "string", "phone_number": "string } |
GET | /getUser | Gets logged in user | content-type: applicaton/json x-access-token: token |
|
POST | /addContact | Adds a contact to signed in user | content-type: applicaton/json x-access-token: token |
{ "contact_name": "string", "contact_phone_number": "string" } |
GET | /getContacts | Gets all contacts for signed in user | content-type: applicaton/json x-access-token: token |
|
DELETE | /deleteContact/{phone_number} | Delete contact from signed in user | content-type: applicaton/json x-access-token: token |
|
POST | /sendSms | Send sms from signed in user to contact | content-type: applicaton/json x-access-token: token |
{ "receiver_phone_number": "string", "message": "string" } |
GET | /getSms/{phone_number} | Get SMSs sent from contact to signed in user | content-type: applicaton/json x-access-token: token |
|
PUT | /updateStatus | Update the read status of an SMS message thread | content-type: applicaton/json x-access-token: token |
{ "message_thread": "string" } |