Reputation: 11
I start in Angular 5, I want to display the list of Cities from a JAX-RS API, then I get the following error :
Http failure response for http://localhost:4200/api/: 404 Not Found
Here you will find my files with which I work :
ville.service.ts
import {Injectable} from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Ville } from '../models/ville.model';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable()
export class VilleService {
constructor(private http:HttpClient) {}
private userUrl = '/api/';
public getVilles() {
return this.http.get<Ville[]>(this.userUrl);
}
public deleteVille(ville) {
return this.http.delete(this.userUrl + "/"+ ville.idVille);
}
public createVille(ville) {
return this.http.post<Ville>(this.userUrl, ville);
}
}
proxy.config.json
{
"/api/*": {
"target": "http://localhost:8080/QuickDep/Compagne",
"secure": false
}
}
in package.json
"start": "ng serve --proxy-config proxy.config.json",
Upvotes: 1
Views: 13694
Reputation: 11
Try:
{
"/api": {
"target": "http://localhost:8080/QuickDep",
"secure": false,
"changeOrigin": true
}
}
Upvotes: 0