我有POST API,该API始终会发布正文,但是我必须在POST之前执行GET API,并且仅当我的GET API响应中不存在记录时才进行发布。任何帮助将不胜感激?
我的示例POST:
fetch('posturl', {
method: 'POST',
mode: 'cors',
body: JSON.stringify({
Memberno: '10'
})
})
.then(function (response) {
return response.json();
答案 0 :(得分:0)
let getResult = await fetch('geturl', {
method: 'GET',
mode: 'cors',
body: JSON.stringify({
Memberno: '10'
})
});
// you should also probably check for statusCode if it's between 200-299
if (getResult.body !== undefined || getResult.body !== null) {
// doPost ...