The Request
interface of the Fetch API represents a resource request.
class App extends React.Component {
...
_deleteItem(id) {
const myRequest = new Request(`http://localhost:3000/data/${id}`, {
method: "DELETE"
});
/**
* myRequest.url
* - "http://localhost:3000/data/1"
* myRequest.method
* - "DELETE"
*/
fetch(myRequest).then(res => {
console.log(res); // Response {... status: 200, …}
if (res.status === 200) {
fetch("http://localhost:3000/data")
.then(res => {
return res.json();
})
.then(data => {
this.setState({
list: data
});
});
}
});
}
}
参考资料:
https://developer.mozilla.org/zh-CN/docs/Web/API/Request
axios
.post("http://localhost:3000/user")
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err.response);
console.error(err.response.status);
// const { data } = err.response;
});
return;
fetch(
"http://data-pipeline.edge.zylliondata.local/api/v3/data-pipeline/task",
{
method: "post",
body: JSON.stringify({
name: "默认的任务名称",
description: "Second data-preprocessing task",
dataPipeline: [
{
processId: "100",
hdfsExtract: {
hdfsPath: "/meta/ign.csv",
sep: ",",
encoding: "UTF-8",
format: "csv"
},
data: {
schema: {},
data: []
},
status: "",
errorLog: ""
}
],
frontendData: {}
}),
headers: {
"content-type": "application/json"
}
}
)
.then(res => {
return res.json();
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
网友评论