test fetch api

by puuga

JavaScript

let myHeader = new Headers({
	'x-api-key': 'a8317f9c3628159a6c45c35583ed0c5c',
	'Authorization': 'Basic YXBpbW9iaWxlOmtBQjZBc3dl'
})

let mySetting = {
	method: 'GET',
	headers: myHeader,
	mode: 'cors'
}

console.log(myHeader.has("x-api-key")); // true
console.log(myHeader.has("Authorization")); // true

// let prodUrl = 'https://gen365api.generali.co.th/main/...'
// let testUrl = 'https://gen365api-uat.generali.co.th/main/...'
let myUrl = 'http://192.168.2.19/api/privilege/index.json?id=460'

let myRequest = new Request(myUrl, mySetting)

fetch(myRequest).then((response) => {
	console.log(`response.status: ${response.status}`)
	if (response.ok) {
		console.log(`response.ok: ${response.ok}`)
		return response.json()
	}
	throw new Error(response.statusText)
}).then((json) => {
	console.log(`json: ${json}`)
  console.log(json)
}).catch(function(error) {
	console.log('There has been a problem with your fetch operation: ' + error.message)
	console.log(error)
})