📌

ブラウザのコンソールからAPIをPOSTで叩く方法

2023/05/18に公開
const url = 'https://httpbin.org/';
const data = { username: 'example' };

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.error('Error:', error));

参考
https://developer.mozilla.org/ja/docs/Web/API/Fetch_API/Using_Fetch#json_データのアップロード

https://httpbin.org/

Discussion