I'm trying to perform a GET request to my API endpoint, which returns a JSON response. How do I do this?
Controller.js
oknok.controller('listagemController', function ($scope, $http) {
$scope.init = function () {
$http.get("/api/veiculos")
.then(function (data) {
alert(data.toJSON());
}).catch(function (error) {
alert("Erro ao obter dados!");
});
}
});
Response from API when I execute curl in terminal
curl http://localhost:8181/api/veiculos
{
"_links" : {
"self" : {
"href" : "http://localhost:8181/api/veiculos"
}
},
"_embedded" : {
"veiculos" : [ {
"nome" : "daniela",
"tipo" : "tipo",
"_links" : {
"self" : {
"href" : "http://localhost:8181/api/veiculos/559d59b1ccf2ebb2fc97e70e"
},
"contatos" : {
"href" : "http://localhost:8181/api/veiculos/559d59b1ccf2ebb2fc97e70e/contatos"
},
"clientes" : {
"href" : "http://localhost:8181/api/veiculos/559d59b1ccf2ebb2fc97e70e/clientes"
}
}
} ]
},
"page" : {
"size" : 20,
"totalElements" : 1,
"totalPages" : 1,
"number" : 0
}
}
JSON.stringifyand works! How do I get "nome" and "tipo" from veículo? Only access _embedded, veículo...?