JavaScript: Fetch API та HTTP-запити

POST, заголовки та опції fetch

📖 Теорія
JavaScript
1class="hl-comment">// POST з JSON-тілом
2async class="hl-keyword">function createPost(data) {
3  class="hl-keyword">const response = await fetch(class="hl-string">'https:class="hl-comment">//api.example.com/posts', {

method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer my-token',
'X-Custom-Header': 'value'
},

💡 Приклад коду
Вивід: