This is a simple API for educational purposes
- Create an account in mlab.com
- In your dashboard you will see
MongoDB Deployments
click the buttoncreate new
- select the cloud provider that you want and select
single-node
andsandbox
plan and name it
Once your database is created we need to create the users.
- Select the tab users and create an user for that database
In order to connect using the driver you need to copy the address similar to this one.
mongodb://<dbuser>:<dbpassword>@ds1516621.mlab.com:51661/phoneapi
Modify dbuser
and dbpassword
with the user that you have created.
Before start you need to rename .env.sample
to .env
and modify the env variable called DATABASE
with your database.
NODE_ENV=development
DATABASE=mongodb://localhost:27017/<DBname>
In terminal run npm install
in order to install all the dependencies. Once all the dependencies are installed type npm start
.
Now you server is running in http://localhost:3000
.
$ npm install
$ npm start
URL | HTTP verb | Request body | Action |
---|---|---|---|
/api/phones |
GET | (empty) | Returns all the phones |
/api/phones |
POST | JSON | Add a new phone |
/api/phones/:id |
GET | (empty) | Returns the specified phone |
/api/phones/:id |
PUT | JSON | Edits the specified phone |
/api/phones/:id |
DELETE | (empty) | Deletes the specified phone |
The phone model has the following structure that you will pass into the body
{
"brand": "Nokia",
"name": "3310",
"image": "http://placekitten.com/200/300",
"specs": [
"barato",
"bonito",
"vintage"
]
}