Check out a free preview of the full Building Awesomer Apps with Angular course:
The "Demo Application Q&A" Lesson is part of the full, Building Awesomer Apps with Angular course featured in this preview video. Here's what you'd learn in this lesson:

Lukas answers questions about integrating with a backend with the demo application and how it relates to using npm-start over ngStart.

Get Unlimited Access Now

Transcript from the "Demo Application Q&A" Lesson

[00:00:00]
>> Lucas Ruebbelke: We had some questions about, are we going to talk about how to integrate with a back end? And the answer is yes, let me explain what is happening in this application. So the reason why we're using npm-start and not ng serve is because concurrently, we're running not only the Angular CLI server, but we're running a small JSON server.

[00:00:26] And so you see this npm run server, and what JSON server does is it takes a,
>> Lucas Ruebbelke: Basically a static JSON file and converts it into a REST API. And so if we go to port 3000,
>> Lucas Ruebbelke: You can see here that we have two endpoints, items and widgets, and so let me just boost this up.

[00:00:56] And so, you can see here that it takes essentially a key value collection, and it turns it into a REST API here. So now, items for instance, so then you do forward slash one. And it will return just this one, so this is a really, really convenient way to spin up a REST API.

[00:01:17] So if don't take anything else today, take this hashtag protip, this is the easiest way to get a REST API up and running, is if you can just right out in JSON, then boom you have a REST API. Insomuch that, because rest is conventional, like the verb, so once you understand it you can just do it all day long.

[00:01:40] It doesn't matter if you're on .Net, Ruby, whatever. Is that I have been on projects where the front-end team that I was on was working faster than the back-end team could produce REST APIs. But because we agreed on the shape and the endpoints, we just did it in JSON server, and when they finished we just swapped the endpoints out and we were good to go.

[00:02:02] So the point is yes, we're going to talk about how to integrate with the back end via a REST API, we are just running a very lightweight local one. And so that is what is happening here. So we're basically running the front end app on port 4200, and the back end REST API on port 3000.