Back End: Node.js with the Express.js framework
Database: MongoDB hosted w/ mLab and Mongoose as the ODM
-
Messages are stored in the database using the following Mongoose Schema:
{ title: String, content: String, isPalindrome: Boolean }
Front End: HTML/JavaScript/Bootstrap
The application has been tested and deployed on a DigitalOcean VPS via docker. The Dockerfile is included in this repository.
The following instructions require you to have:
- NPM and Docker installed
- Ubuntu (Other OSes will most likely work but I have not tried them myself).
- Clone this repository:
git clone https://github.com/filiptodoric/simple-message-restapi.git
- Move into the newly created directory and run:
npm install
This will install all the dependencies from thepackage.json
file. - When NPM is finished installing, start the server:
npm start
localhost:8080
on your web browser. Server is now running locally.
(Mocha and Chai are included as dev dependicies in this package.
This means everything should work fine, however, if you get an error you may need to install
them globally with the -g
flag.)
- In terminal start the server. (
npm start
or./bin/www
) - In another terminal window run the tests with
mocha
- Tada! The tests have ran. Results will be outputted to the terminal.
- SSH into your server.
- Clone this repository to the home directory:
git clone https://github.com/filiptodoric/simple-message-restapi.git
- Move into the newly created directory.
To create a container from the image run the following command in terminal:
docker build -t simple-restapi .
docker run -p 80:8080 -d simple-restapi
Docker maps port 8080
inside the container to port 80
of the machine. Visit the IP of your server and you will now have the API running.
API requests are prefixed with /api/
- For example: localhost/api/messages
GET /messages
- Use: Get all the messages in the database.
- Returns: a JSON array of all the messages in the database.
POST /messages
- Use: Creates a new message and saves it to the database.
- Request: in the body include:
title: String
andcontent: String
. - Returns:
{ message: 'New message has been created.'}
At this point the message is evaluated on whether or not it is a palindrome. This is saved as a Boolean in the database.
GET /messages/:message_id
- Use: Gets a spsecefic message
- Return: message with the specified ID as a JSON.
DELETE /messages/:message_id
- Use: Deletes the message with the specified ID from the database.
- Returns:
{ message: 'The message has been deleted.'}