play login data in API parameter

Asked

Viewed 62 times

0

In the login I ask the user to put the email and Cpf, then I have an api that plays data in a table that I created, then I need to take the parameters Cpf and email to put in the api.

Ex:

http://8080/rest/apiCODCPF=02798477425&EMAIL=fulano%40fulano.com.br

How can I take email and Cpf data and play as a parameter in the api?

I just have the api link, I have nothing else

Code to show the api data:

    function load(){

  var xhr = new XMLHttpRequest();
  xhr.open("GET", "http://localhost/r/TRCKCLI?CODCPF=12345678901&EMAIL=fulano%40email.com");



  xhr.addEventListener("load", function() {
      var resposta = xhr.responseText;
      // console.log("ola1");
      var clientes = JSON.parse(resposta);
      // console.log("ola2");
      // console.log(clientes);

      for (var i =0; i < 1; i++){
          // console.log("ola3");
         var clientes_1 = clientes.TRACKER[i];
         AdicionaNome(clientes_1);
         AdicionaCPF(clientes_1);
         AdicionaProduto(clientes_1);
         AdicionaCidade(clientes_1);
         AdicionaCodigoProduto(clientes_1);
         AdicionaCodigoCliente(clientes_1);
         AdicionaStatus(clientes_1);
         ActiveStatusImage(clientes_1);
         ActiveOnlyPostagem(clientes_1);
         adicionaClienteNaTabelaViagem(clientes_1);
         ActiveQtdViagem(clientes_1);


     }

  });

  xhr.send();
      }
      window.onload = load;
  • This API you created? Did someone create and tell you to consume it? If it’s a third party, you have to know how it is: GET/POST, what you went through would be via GET. Another detail, the link looks like this: 'http://8080/Rest/apiCODCPF', it wouldn’t be 'http://nameplate:8080/Rest/api/', you can see that putting the localdaapi name and a bar after the word API.

  • Exactly, they created and ordered me to consume her

  • I completed my comment above...

  • The link I put in the api is modified, just an example, you know? I knew how to consume it and show the data on the site, only I need to put Cpf and email as a parameter, as I said in the question

  • Put the code of what you’re trying to...

  • Ready. That’s how I can show the api on the site (api data)

Show 2 more comments

1 answer

1

If it is in this format use:

$email = $_GET['EMAIL'];
$cpf   = $_GET['apiCODCPF'];
  • And I throw it where?

  • In the file the URL points to. Email and CPF are being passed as GET

  • Which in case is where I add the API?

  • You put it on the server: client -> request(GET) ->server

  • I’m sorry, but I don’t understand

  • 2

    Study a little more about REST-style API architecture

  • Right. But to do this Voce said I need to have access to api? pq I just have her link, you know?

Show 2 more comments

Browser other questions tagged

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