Vupt

by Raphael Quintao

HTML

<button onclick="make_request()">Teste</button>

<pre id="resp">Click to test api</pre>

CSS

html, body {
  background: hsl(217, 11%, 14%);
  color: hsl(0, 0%, 80%);
}

JavaScript

function process(body) {
  var username = 'api';
  var password = '123123';
  
  var resp = document.getElementById('resp');
  resp.id = 'resp';
  resp.innerText = 'Loading...';
  
  fetch('http://localhost:8000/process', {
    method: 'POST',
    mode: 'cors',
    headers: {
      'Authorization': 'Basic ' + btoa(`${username}:${password}`),
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
  }).then(r => r.json())
    .then((r) => {  	
    resp.innerText = JSON.stringify(r, null, 4);
  });  
}

function make_request() {
  var body = {
    "cpf": "774.792.570-07",
    "cnpj": "75.643.044/0001-39",
    "valor_solicitado": "20000",
    "uf": "MG",
    "cidade": "Belo Horizonte",
    "nome_responsavel": "Jhon",
    "telefone_responsavel": "999999999",
    "email_responsavel": "[email protected]",
    "renda_socio": "222222"
  };

  process(body);
}