« Axios » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
(→Get) |
Aucun résumé des modifications |
||
Ligne 10 : | Ligne 10 : | ||
const axios = window.axios; | const axios = window.axios; | ||
</script> | </script> | ||
</kode> | |||
= Instance = | |||
<kode lang='js'> | |||
const instance = axios.create({ | |||
baseURL: 'https://www.domain.net/api' | |||
}); | |||
</kode> | </kode> | ||
Ligne 15 : | Ligne 22 : | ||
<kode lang='js'> | <kode lang='js'> | ||
const instance = axios.create({ | const instance = axios.create({ | ||
auth: { | auth: { | ||
username: 'xxx', | username: 'xxx', | ||
Ligne 25 : | Ligne 31 : | ||
= Get = | = Get = | ||
<kode lang='js'> | <kode lang='js'> | ||
instance.get('/item?api-version=1') | instance.get('/item?api-version=1') | ||
.then(function (response) { | .then(function (response) { |
Version du 27 janvier 2021 à 19:09
Links
Client side
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script> const axios = window.axios; </script> |
Instance
const instance = axios.create({ baseURL: 'https://www.domain.net/api' }); |
Authentication
const instance = axios.create({ 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)); |