MinUk.Dev
Fetch 문법 간단 정리 - minuk dev wiki

Fetch 문법 간단 정리

created : Tue, 07 Apr 2020 20:22:29 +0900
modified : Tue, 15 Mar 2022 02:33:06 +0900

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