.NET Core 2.0 with Angular 4 and MySQL
- For the previous part check out: Part 8 – Creating Angular4 client side – Navigation and routing – – This post is divided into several sections: – – The thing that matters is that we are going to use the new HttpClientModule introduced in Angular 4.3 and not the old HttpModule.
- So in the development mode, it should send requests towards localhost:5000, and in the production environment to some other address.
- Angular knows if it is production or development environment (because of “production” property values inside both environment files) and is going to supply us with a valid value of that urlAddress.
- Now we need to import this service into our app.module.ts file: – – Place it inside providers array as well: – – Let’s configure the HttpClientModule and create the repository service.
- The second function, create, is a wrapper for POST requests.
Part 9 is focused on creating a repository with the Angular HTTP requests, on the client side. In this complete series, you will learn how to develop web app by using.NET Core 2.0, Angular 4, and MySQL. Also, we will post the app on Windows and Linux environment.
@dotnetkicks: .NET Core 2.0 with Angular 4 and MySQL – Part 9 Angular HTTP by VladaPecanac #dotnet via DotNetKicks
While sending HTTP requests towards our server, we need to use the HTTP Angular protocol. Of course, we may handle all the HTTP requests from every component and process the response as well, but it is not a good practice. It is much better to make the repository for your requests and then send the request URL to that repository. The repository should take care of the rest.
How do we achieve this?
That’s the topic of this blog post.
If you want to see all the basic instructions and complete navigation for this series, check out the following link: Introduction page for this tutorial.
For the previous part check out: Part 8 – Creating Angular4 client side – Navigation and routing
The source code is available at GitHub .NET Core, Angular 4 and MySQL. Part 9 – Source Code
This post is divided into several sections:
The thing that matters is that we are going to use the new HttpClientModule introduced in Angular 4.3 and not the old HttpModule. The new module gives us some advantages with processing responses and handling errors as well. With the old HttpModule, we would have to map our response and convert it to the JSON. Consequently, we would have to use the RxJS library because this library enables usage of the map function. With the new HttpClientModule, JSON response is set by default. Thus our project requires no result conversion at all.