美文网首页
Fetch API 笔记

Fetch API 笔记

作者: 不知道的是 | 来源:发表于2018-06-26 12:59 被阅读0次

    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);
            });
    

    <https://jsonplaceholder.typicode.com/>

    相关文章

      网友评论

          本文标题:Fetch API 笔记

          本文链接:https://www.haomeiwen.com/subject/elnpyftx.html