I am using the newest HttpClient
module in Angular5
to send a get request for local json, but I keep receiving a 404 error. I have already imported the HttpClientModule
into my app.module.ts
.
Here is a snapshot of my folder structure:
https://i.sstatic.net/HcFof.png
I am trying to make the call from the blog-detail component for the blog-list.json
. Below is the code snippet:
constructor(private http: HttpClient) {
}
ngOnInit(): void {
// this.http.get('https://jsonplaceholder.typicode.com/posts/1').subscribe((data:Blog[]) => {
this.http.get('app/api/blog-list.json').subscribe((data:Blog[]) => {
this.blogs = data;
});
}
The error message I receive is as follows:
GET http://localhost:909/app/api/blog-list.json 404 (Not Found)
When attempting to open the file directly in the browser by clicking http://localhost:909/src/app/api/blog-list.json, the application itself is served rather than the intended json file.
Kindly note that while requests to a REST API on the web are successful, calls solely to a local json file seem to fail.