From the course: Angular: API Communication and Authentication
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
POST route for the API - Angular Tutorial
From the course: Angular: API Communication and Authentication
POST route for the API
- [Instructor] Now that we have our get route for retrieving our contacts, we need to setup a post route that we can use to add new contacts. When performing a post request data is sent in the body of the request. We can go ahead and use the body parser middleware in order to parse incoming requests. We need our API to parse JSON, so we use the bodyParse.json middleware function, which will make the data available in the body of the request in our handlers. I've made a small change. Instead of just having our route at the forward slash contacts, I've prepended the forward slash API route. It's a standard convention to follow when developing your own API. Similar to our get request, we listen for post requests at the forward slash API slash contacts route. We can retrieve the user being added in the body of the request. This is thanks to our body parser middleware function. Next, we obtain a reference to the contacts collection, and then we make call to insert the posted user using the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
GET route for the API4m 55s
-
(Locked)
POST route for the API3m 54s
-
(Locked)
Using @angular/http to retrieve contacts, part 13m 8s
-
(Locked)
Using @angular/http to retrieve contacts, part 23m 52s
-
(Locked)
Creating a new route for adding a new contact6m 12s
-
(Locked)
Using ngForm for form submission2m 49s
-
(Locked)
Writing the onSubmit() function4m 16s
-
-
-
-
-