Last active
April 5, 2018 11:31
-
-
Save mtarnovan/9b58ee458471c0e7b1c1c95b1bd268ae to your computer and use it in GitHub Desktop.
openapi.ro test request from browser js console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const apiKey = prompt('Introdu cheia ta API. Aceasta o gasesti in contul tau openapi') | |
var testCIF = prompt('Introdu un CIF valid sau lasa gol pentru un CIF de test') || '13548146' | |
const xhr = new XMLHttpRequest() | |
xhr.open('GET', `https://api.openapi.ro/v1/companies/${testCIF}`, true) | |
xhr.setRequestHeader('x-api-key', apiKey) | |
xhr.send() | |
const processResponse = (e) => { | |
if (xhr.readyState == 4) { | |
if (xhr.status == 200) { | |
window.openapiResponse = JSON.parse(xhr.responseText) | |
console.log(window.openapiResponse) | |
} | |
else { | |
console.error(`Statusul raspunsului de la server nu este 2xx: ${xhr.status}, indicand o eroare. Raspunsul de la server:`) | |
console.log(xhr.responseText) | |
} | |
} | |
} | |
xhr.onreadystatechange = processResponse | |
"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment