« Axios » : différence entre les versions
Apparence
Ligne 32 : | Ligne 32 : | ||
console.error(error); | console.error(error); | ||
}); | }); | ||
const getItemById = async (id) => | |||
azure.get(`/item/${id}`) | |||
.then(function (response) { | |||
const item = response.data.value; | |||
return item; | |||
}) | |||
.catch(function (error) { | |||
console.error(error); | |||
}); | |||
let item = await getItemById('1'); | |||
$("#result").html(JSON.stringify(item, null, 4)); | |||
</kode> | </kode> |
Version du 27 janvier 2021 à 19:07
Links
Client side
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
const axios = window.axios;
</script>
|
Authentication
const instance = axios.create({
baseURL: 'https://www.domain.net/api',
auth: {
username: 'xxx',
password: 'yyy'
}
});
|
Get
instance.get('/item?api-version=1')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.error(error);
});
const getItemById = async (id) =>
azure.get(`/item/${id}`)
.then(function (response) {
const item = response.data.value;
return item;
})
.catch(function (error) {
console.error(error);
});
let item = await getItemById('1');
$("#result").html(JSON.stringify(item, null, 4));
|