Fetch 문법 간단 정리

created : 2020-04-07T11:22:29+00:00
modified : 2022-03-14T17:33:06+00:00

js fetch

Basic Usage

    const queryData = {
    	query:`
    query {
      hello,
      persons {
        name,
      }
    }`
    };
    const headers = new Headers({
      "Accept" : "application/json",
      "Content-Type" : "application/json"
    });

    const fetchPromise = fetch('/graphql', {
        headers,
        method: "POST",
        body: JSON.stringify(queryData),
    });

    fetchPromise
    	.then(response => response.clone().json()) // avoid reponse lock
    	.then(data => console.log);