Using Angular version 15.0 has been smooth sailing on the backend, but when making service requests on the frontend, an error is encountered:
Failed to load resource: the server responded with a status of 404 (Not Found)
This is due to the request URL:
http://localhost:4200/api/commodityTypes/getAllCommodityTypes
On the other hand, accessing the same URL through Swagger works fine:
https://localhost:5001/api/CommodityTypes/getAllCommodityTypes retrieves data successfully.
The service code snippet for this issue is as follows:
@Injectable({
providedIn: 'root'
})
export class CommodityTypesService {
private baseUrl = 'api/commodityTypes';
constructor(private http: HttpClient) { }
/** GET all commodityTypes from the server */
getAllCommodityTypes(): Observable<CommodityType[]> {
return this.http.get<CommodityType[]>(this.baseUrl + '/getAllCommodityTypes/');
}
// rest of your code ...
}
The encountered error message is:
HttpErrorResponse
error:
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot GET /api/commodityTypes/getAllCommodityTypes/</pre>\n</body>\n</html>\n"
headers:
HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message:
"Http failure response for http://localhost:4200/api/commodityTypes/getAllCommodityTypes/: 404 Not Found"
name:
"HttpErrorResponse"
ok:
false
status:
404
statusText:
"Not Found"
url:
"http://localhost:4200/api/commodityTypes/getAllCommodityTypes/"
[[Prototype]]:
HttpResponseBase
How can this issue be resolved?