Skip to content

Instantly share code, notes, and snippets.

@mtarnovan
Last active April 5, 2018 11:31
Show Gist options
  • Save mtarnovan/9b58ee458471c0e7b1c1c95b1bd268ae to your computer and use it in GitHub Desktop.
Save mtarnovan/9b58ee458471c0e7b1c1c95b1bd268ae to your computer and use it in GitHub Desktop.
openapi.ro test request from browser js console
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