3.0 KiB
Message API using Express js, Mongoose and Heroku
Description
Wrote up a RESTful API using Node.js, Express js for the main logic and implementation.
I connected this app to Heroku for cloud deployment and am using mongoose for the database implementation.
The web app itself can be accessed [here](https://gregs-rest-api-demo.herokuapp.com) and
you can make curl calls yourself using the URL https://gregs-rest-api-demo.herokuapp.com.
For the actual API architeture itself I implemented GET, POST, PUT and DELETE calls.
The messages themselves consist of and id, a message and a time stamp for when the message was created.
The id can be used to find a specific message for the GET, PUT and DELETE calls.
The id is always taken from the request parameter whereas the message is taken from the request body.
The message Schema is as follows:
`id: {type:Number, required:true},
message: {type:String, required:true},
time: {type:Date, required:true}`
Libraries and tools used
How to
Build
Clone this repository and install dependencies
git clone git@github.com:gjcampbell777/RESTapi_demo.git cd express-rest-api npm install
Deploy
Locally
Fire up the local server
node server.js
Cloud
If you have your own HEROKU_API_KEY you can run:
git push heroku
Access
Locally
The web app can now be reached locally at:
http://localhost:3000/
Cloud
The web app can be accessed through your heroku URL
REST API Documentation
All of the calls below can be done using services like Postman or through curl commands with
the URL https://gregs-rest-api-demo.herokuapp.com.
GET
To get info on all messages use
/msg
To get info on one message use
/msg/:id
The id info is taken from the parameter
POST
To send a message use
/msg/:id
The id info is taken from the parameter, the message info is taken from a json body containing a message key
and the timestamp is taken from the API logic
PUT
To update a message use
/msg/:id
The id info is taken from the parameter and the new message info is taken from a json body containing a message key
DELETE
To delete all messages use
/msg
To delete one message use
/msg/:id
The id info is taken from the parameter
Example of desired inputs:
URL: https://gregs-rest-api-demo.herokuapp.com/msg/5 body: {"message":"test"}
Server Logs
Server logs can be found using the HEroku CLI command `heroku logs` within the repo once the web app is deployed
Licence
MIT