{"id":11322,"date":"2021-06-16T20:57:18","date_gmt":"2021-06-16T11:57:18","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=11322"},"modified":"2021-06-16T20:57:18","modified_gmt":"2021-06-16T11:57:18","slug":"fetch-api%eb%a5%bc-%ec%9d%b4%ec%9a%a9%ed%95%9c-rest-api-%ed%98%b8%ec%b6%9c","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=11322","title":{"rendered":"fetch API\ub97c \uc774\uc6a9\ud55c REST API \ud638\ucd9c"},"content":{"rendered":"<p>2\uac1c REST API\ub97c \uc21c\ucc28\uc801\uc73c\ub85c \ud638\ucd9c\ud558\ub294 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\nconst url1 = \"http:\/\/localhost:8080\/Xr?qryHub|0004259886\";\r\nconst url2 = \"http:\/\/localhost:8080\/Xr?qryHub|0002097186\";\r\n\r\nfetch(url1).then(response => {\r\n    return response.json();\r\n}).then(json => {\r\n    console.log(\"First\", json);\r\n    return fetch(url2);\r\n}).then(response => {\r\n    return response.json();\r\n}).then(json => {\r\n    console.log(\"Second\", json);\r\n}).catch(function (error) {\r\n    console.warn(error);\r\n});\r\n<\/pre>\n<p>url1\uc5d0 \ub300\ud55c REST API\uc758 \ud638\ucd9c\uc774 \uc131\uacf5\ud558\uba74 url2\uc5d0 \ub300\ud55c REST API\uac00 \ud638\ucd9c\ub429\ub2c8\ub2e4. \uc774 \ub450 \uac1c\uc758 REST API\uac00 \ubb38\uc81c\uac00 \uc5c6\ub2e4\uba74 \uacb0\uacfc\uac00 \ud638\ucd9c\ub41c \uc21c\uc11c\ub300\ub85c \uc544\ub798\ucc98\ub7fc \ucf58\uc194\uc5d0 \ud45c\uc2dc\ub429\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2021\/06\/fetch_1.png\" alt=\"\" width=\"500\" class=\"aligncenter size-full wp-image-11323\" \/><\/p>\n<p>\uc704\uc758 \ucf54\ub4dc\ub97c \ubcf4\uba74 2\uac1c\uc758 REST API\ub294 \uadf8 \uacb0\uacfc\uc5d0 \uc885\uc18d\uc801\uc774\uc9c0 \uc54a\uc73c\ubbc0\ub85c \uc21c\ucc28\uc801\uc73c\ub85c \ud638\ucd9c\ud558\uc9c0 \uc54a\uace0 \ub3d9\uc2dc\uc5d0 \ud638\ucd9c\ud558\ub294 \uac83\uc774 \ud6a8\uc728\uc801\uc785\ub2c8\ub2e4. \uc544\ub798\uc758 \ucf54\ub4dc\ub294 \uc774 2\uac1c\uc758 REST API\ub97c \ub3d9\uc2dc\uc5d0 \ud638\ucd9c\ud558\uc5ec 2\uac1c\uc758 \uacb0\uacfc\ub97c \ucde8\ud569\ud574 \ucd9c\ub825\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\nconst url1 = \"http:\/\/localhost:8080\/Xr?qryHub|0004259886\";\r\nconst url2 = \"http:\/\/localhost:8080\/Xr?qryHub|0002097186\";\r\n\r\nPromise.all([fetch(url1), fetch(url2)]).then(responses => {\r\n    return Promise.all(responses.map(response => {\r\n        return response.json();\r\n    }));\r\n}).then(json => {\r\n    console.log(json);\r\n}).catch(error => {\r\n    console.log(error);\r\n});\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2021\/06\/fetch_2.png\" alt=\"\" width=\"500\" class=\"aligncenter size-full wp-image-11326\" \/><\/p>\n<p>\uc9c0\uae08\uae4c\uc9c0 \uc0b4\ud3b4\ubcf4\uba74 REST API\ub294 GET \ubc29\uc2dd\uc778\ub370\uc694. POST \ubc29\uc2dd\uc744 fetch API\ub85c \ud638\ucd9c\ud558\ub294 \ucf54\ub4dc\uc758 \uc608\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\nconst url = \"http:\/\/localhost:8080\/Xr?sql|postgis|1\";\r\nfetch(url, {\r\n    method: \"POST\",\r\n    \/\/headers: { 'Content-Type': 'text\/plain;charset=UTF-8' },\r\n    body: `\r\n        SELECT 0 as project_id, zone_id, hub_id\r\n        FROM zone_hub_map\r\n        WHERE zone_id\r\n        IN (\r\n            SELECT zone_id FROM project_zone_map WHERE project_id = 0\r\n        );\r\n    `\r\n}).then(response => {\r\n    return response.text();\r\n}).then(text => {\r\n    console.log(text);\r\n});\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2021\/06\/fetch_3.png\" alt=\"\" width=\"700\" class=\"aligncenter size-full wp-image-11330\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2\uac1c REST API\ub97c \uc21c\ucc28\uc801\uc73c\ub85c \ud638\ucd9c\ud558\ub294 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4. const url1 = &#8220;http:\/\/localhost:8080\/Xr?qryHub|0004259886&#8221;; const url2 = &#8220;http:\/\/localhost:8080\/Xr?qryHub|0002097186&#8221;; fetch(url1).then(response => { return response.json(); }).then(json => { console.log(&#8220;First&#8221;, json); return fetch(url2); }).then(response => { return response.json(); }).then(json => { console.log(&#8220;Second&#8221;, json); }).catch(function (error) { console.warn(error); }); url1\uc5d0 \ub300\ud55c REST API\uc758 \ud638\ucd9c\uc774 \uc131\uacf5\ud558\uba74 url2\uc5d0 \ub300\ud55c REST API\uac00 \ud638\ucd9c\ub429\ub2c8\ub2e4. \uc774 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=11322\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;fetch API\ub97c \uc774\uc6a9\ud55c REST API \ud638\ucd9c&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88],"tags":[],"class_list":["post-11322","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/11322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11322"}],"version-history":[{"count":9,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/11322\/revisions"}],"predecessor-version":[{"id":11335,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/11322\/revisions\/11335"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11322"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}