From b4e90847af4703b12baa381cbceb624ae3af52fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Rudolf?= Date: Wed, 21 Oct 2026 11:16:53 +0200 Subject: [PATCH] Rest API teszt --- rest/fetch.js | 25 +++++++++++++++++++++++++ rest/index.html | 12 ++++++++++++ rest/posts.js | 15 +++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 rest/fetch.js create mode 100644 rest/index.html create mode 100644 rest/posts.js diff --git a/rest/fetch.js b/rest/fetch.js new file mode 100644 index 0000000..d468b5e --- /dev/null +++ b/rest/fetch.js @@ -0,0 +1,25 @@ + +// fetch('https://jsonplaceholder.typicode.com/posts') +// .then(res=>res.json()) +// .then(adatok=>console.log(adatok)) +// .catch(err=>console.log(err)) + + + + + +async function letolt() { + try { + let keres=await fetch('https://jsonplaceholder.typicode.com/posts/1'); + let valasz=await keres.json(); + + console.log(valasz); + + } catch (error) { + console.log(error); + } +} + +letolt(); + +console.log("Valami"); \ No newline at end of file diff --git a/rest/index.html b/rest/index.html new file mode 100644 index 0000000..68efde9 --- /dev/null +++ b/rest/index.html @@ -0,0 +1,12 @@ + + + + + + Posts + + + + + + \ No newline at end of file diff --git a/rest/posts.js b/rest/posts.js new file mode 100644 index 0000000..fbddbfc --- /dev/null +++ b/rest/posts.js @@ -0,0 +1,15 @@ +let keres=new XMLHttpRequest(); +let valasz=""; + +keres.open('GET','https://jsonplaceholder.typicode.com/posts',true); + +keres.onload=function(){ + valasz=JSON.parse(this.response); + console.log(valasz); +} + +keres.send(); + +console.log("Válasz:"+valasz); + +