1
Next, I’m not getting a request for an api, a get. Follow the api’s code and answer.
User model.:
export interface ResponseUsers {
data:User;
}
export interface User {
id: number;
nome: string;
email: string;
login: string;
admin: boolean;
}
Userservice:
@Injectable({
providedIn: 'root'
})
export class UserService {
public url = "https://combustivelapp.herokuapp.com/api/usuarios";
constructor(private http: HttpClient) { }
getUser(): Observable<ResponseUsers> {
return this.http.get<ResponseUsers>(this.url);
}
}
HTML list with data:
<tr *ngFor="let user of responseUsers.data">
<th scope="row" text-align="center">{{user.id}}</th>
<td>{{user.nome}}</td>
<td>{{user.email}}</td>
<td>{{user.login}}</td>
<td>{{user.admin}}</td>
<td><a routerLink="/users/update/id"> Editar</a></td>
<td><a routerLink="/users/delete/id"> Remover</a></td>
</tr>
Now follow the API data:
Response body:
[
{
"id": 59,
"nome": "wandesson2",
"email": "[email protected]",
"login": "wandessons",
"admin": false
}
Response Header:
connection: keep-alive
content-type: application/json
date: Fri, 30 Oct 2020 05:19:26 GMT
server: Cowboy
transfer-encoding: chunked
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
via: 1.1 vegur
Request URL:
https://combustivelapp.herokuapp.com/api/usuarios
Okay, I think there’s nothing else missing. Could someone give me a hand?