To solve our empty database and before we create our frontend interface, let's add some data with the Chrome extension Postman. By the way, it's a very useful browser interface to work with RESTful APIs.
As we already know that our database is empty, our first task is to insert a record. To do so, perform the following steps:
http://localhost:8080/api/speakers
. Select the x-www-form-urlencoded option and add the properties of our model:var SpeakerSchema = new Schema({ name: { type: String, default: '' }, company: { type: String, default: '' }, title: { type: String, default: '' }, description: { type: String, default: '' }, picture: { type: String, default: '' }, schedule: { type: String, default: '' }, createdOn: { type: Date, default: Date.now} });
http://localhost:8080/api/speakers
in the browser again.{ "_id": "53a38ffd2cd34a7904000007", "__v": 0, "createdOn": "2014-06-20T02:20:31.384Z", "schedule": "10:20", "picture": "fernando.jpg", "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod...", "title": "MongoDB", "company": "Newaeonweb", "name": "Fernando Monteiro" }
_id
from the preceding JSON file and add to the end of the http://localhost:8080/api/speakers/53a38ffd2cd34a7904000005
URL and click on Send. You will see the same object on the screen.Take a look at your terminal, you can see four messages that are the same: An action was performed by the server. We configured this message in the server.js
file when we were dealing with all routes of our API.
router.use(function(req, res, next) { // Give some message on the console console.log('An action was performed by the server.'), // Is very important using the next() function, without this the Route stops here. next(); });
This way, we can monitor all interactions that take place at our API.
Now that we have our API properly tested and working, we can start the development of the interface that will handle all this data.
18.119.160.181