Consume API with mandatory parameters

Asked

Viewed 200 times

0

if I have an API that requires two mandatory parameters to be consumed, how should I insert them in a $http request?

self.buscaPrestadores = function()
{  
    $http({
            method: 'GET',
            url: self.urlPrestadores,
            headers: { 'Content-Type': 'application/json' }
            data: {'parametro1':abc,'parametro2':abc }
    }).then(function(resposta) { 
         var json = {};
         json = resposta.data.data;
         console.log(json);
    })
}

inserir a descrição da imagem aqui

How I try to consume the API from the message below in the developer tab:

inserir a descrição da imagem aqui

  • what’s wrong? data: {uf: 'sp', id_especialidade: 1 } doesn’t work?

  • Yeah, I tried to. Thus: date: {Uf:'ES',id_specialty: 0001 } Continues to accuse error of the state code, which needs to be capitalized. So I wondered if I was doing it right.

1 answer

0


Problem solved:

GET parameters are sent via string in the url so you need to send as a direct parameter in the url, in the case of $http, the structure name is params and not data!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.