Запросы к REST API на JavaScript
Введение | |
GET | |
POST | |
PUT | |
DELETE | |
Другие статьи о JavaScript |
Введение
GET
const options = { method: 'GET', headers: {accept: 'application/json', Authorization: 'Bearer a-proper-token-goes-here'} }; fetch('https://example.com/engine/api/v1/wfs', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
POST
const options = { method: 'POST', headers: { accept: 'application/json', Authorization: 'Bearer a-proper-token-goes-here', 'content-type': 'application/json' }, body: JSON.stringify({ status: 'WAITING', approver_can_revoke: true, target_role_revoked: false, can_bypass_revoke_wf: false, steps: [{name: 'obj_name'}], name: 'name' }) };
PUT
const options = { method: 'PUT', headers: { accept: 'application/json', Authorization: 'Bearer a-proper-token-goes-here', 'content-type': 'application/json' }, body: JSON.stringify({ status: 'WAITING', approver_can_revoke: true, target_role_revoked: false, can_bypass_revoke_wf: false, name: 'name' }) }; fetch('https://example.com/engine/api/v1/wfs/wf_id', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
DELETE
const options = { method: 'DELETE', headers: {accept: 'application/json', Authorization: 'Bearer a-proper-token-goes-here'} }; fetch('https://example.com/engine/api/v1/wfs/wf_id', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
JavaScript | |
Функции | |
typeof(): Определить тип переменной | |
Массивы | |
Сортировка массива | |
Скролл вверх и вниз | |
Определить ширину экрана | |
Mocha Framework | |
Запросы к REST API на JS | |
TicTacToe | |
Ошибки | |
REST |