forked from mustafamuratcoskun/sifirdan-javascript-kursu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c91bc0
commit ef1e38d
Showing
179 changed files
with
24,661 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Ajax,callback , http requests | ||
|
||
class Request{ | ||
|
||
constructor(){ | ||
this.xhr = new XMLHttpRequest(); | ||
} | ||
// Get Request | ||
|
||
get(url,callback){ | ||
|
||
this.xhr.open("GET",url); // Bağlantı açık | ||
|
||
this.xhr.onload = () =>{ | ||
|
||
if (this.xhr.status === 200) { | ||
callback(null,this.xhr.responseText); // İsteğimiz bitti | ||
} | ||
else { | ||
// Hata durumuna | ||
callback("Get Request: Bir hata oluştu",null); | ||
} | ||
|
||
}; | ||
|
||
|
||
this.xhr.send(); | ||
|
||
|
||
} | ||
post(url,data,callback){ | ||
this.xhr.open("POST",url); | ||
this.xhr.setRequestHeader("Content-type","application/json"); // JSON Verisi | ||
|
||
this.xhr.onload = () => { | ||
if(this.xhr.status === 201) { | ||
// Başarılı | ||
callback(null,this.xhr.responseText); | ||
|
||
} | ||
else { | ||
callback("Post Request: Bir hata oluştu",null); | ||
} | ||
|
||
} | ||
|
||
this.xhr.send(JSON.stringify(data)); | ||
|
||
|
||
} | ||
put(url,data,callback){ | ||
this.xhr.open("PUT",url); | ||
this.xhr.setRequestHeader("Content-type","application/json"); // JSON Verisi | ||
|
||
this.xhr.onload = () => { | ||
if(this.xhr.status === 200) { | ||
// Başarılı | ||
callback(null,this.xhr.responseText); | ||
|
||
} | ||
else { | ||
callback("Put Request: Bir hata oluştu",null); | ||
} | ||
|
||
} | ||
|
||
this.xhr.send(JSON.stringify(data)); | ||
|
||
|
||
} | ||
delete(url,callback){ | ||
|
||
this.xhr.open("DELETE",url); // Bağlantı açık | ||
|
||
this.xhr.onload = () =>{ | ||
|
||
if (this.xhr.status === 200) { | ||
callback(null,"Veri silme işlemi başarılı"); // İsteğimiz bitti | ||
} | ||
else { | ||
// Hata durumuna | ||
callback("Delete Request: Bir hata oluştu",null); | ||
} | ||
|
||
}; | ||
|
||
|
||
this.xhr.send(); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
const request = new Request(); | ||
|
||
// request.get("https://jsonplaceholder.typicode.com/albums",function(err,response){ | ||
// if (err === null){ | ||
// // Başarılı | ||
// console.log(response); | ||
// } | ||
// else { | ||
// // Hata | ||
// console.log(err); | ||
// } | ||
|
||
// }); | ||
// request.get("https://jsonplaceholder.typicode.com/albums/51",function(err,response){ | ||
// if (err === null){ | ||
// // Başarılı | ||
// console.log(response); | ||
// } | ||
// else { | ||
// // Hata | ||
// console.log(err); | ||
// } | ||
|
||
// }); | ||
|
||
// request.post("https://jsonplaceholder.typicode.com/albums",{userId:2,title:"Thriller"},function(err,album){ | ||
|
||
// if (err === null){ | ||
// console.log(album); | ||
// } | ||
// else { | ||
// // Hata | ||
// console.log(err); | ||
// } | ||
|
||
|
||
// }) | ||
|
||
// request.put("https://jsonplaceholder.typicode.com/albums/10",{userId:143,title:"Tarkan Karma"},function(err,album){ | ||
|
||
// if (err === null){ | ||
// console.log(album); | ||
// } | ||
// else { | ||
// // Hata | ||
// console.log(err); | ||
// } | ||
|
||
|
||
// }) | ||
request.delete("https://jsonplaceholder.typicode.com/albums/10",function(err,response){ | ||
if (err === null){ | ||
// Başarılı | ||
console.log(response); | ||
} | ||
else { | ||
// Hata | ||
console.log(err); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>AJAX Get,Post,Put,Delete</title> | ||
</head> | ||
<body> | ||
|
||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> |
95 changes: 95 additions & 0 deletions
95
Asenkron Programlama - ES6 , Promise, Fetch/Fetch - Get Request/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
class Request { | ||
|
||
get(url){ // Get Request | ||
return new Promise((resolve,reject)=>{ | ||
fetch(url) | ||
.then(response => response.json()) | ||
.then(data => resolve(data)) | ||
.catch(err => reject(err)); | ||
|
||
}) | ||
|
||
|
||
} | ||
post(url,data){ | ||
|
||
return new Promise((resolve,reject) => { | ||
fetch(url,{ | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
headers: { | ||
"Content-type": "application/json; charset=UTF-8" | ||
} | ||
}) | ||
.then(response => response.json()) | ||
.then(data => resolve(data)) | ||
.catch(err => reject(err)); | ||
|
||
|
||
}) | ||
|
||
|
||
} | ||
|
||
put(url,data){ | ||
return new Promise((resolve,reject) => { | ||
fetch(url,{ | ||
method: 'PUT', | ||
body: JSON.stringify(data), | ||
headers: { | ||
"Content-type": "application/json; charset=UTF-8" | ||
} | ||
|
||
}) | ||
.then(response => response.json()) | ||
.then(data => resolve(data)) | ||
.catch(err => reject(err)); | ||
|
||
|
||
|
||
}) | ||
|
||
} | ||
delete(url){ | ||
|
||
return new Promise((resolve,reject) => { | ||
fetch('https://jsonplaceholder.typicode.com/albums/1', { | ||
method: 'DELETE' | ||
}).then(response => resolve("Veri silme işlemi başarılı")) | ||
.catch(err => reject(err)); | ||
|
||
|
||
}); | ||
} | ||
|
||
} | ||
const request = new Request(); | ||
|
||
// request.get("https://jsonplaceholder.typicode.com/albums") | ||
// .then(albums => { | ||
|
||
// console.log(albums); | ||
// }) | ||
// .catch(err => console.log(err)); | ||
|
||
// request.post("https://jsonplaceholder.typicode.com/albums",{userId:1,title:"Thriller"}) | ||
// .then(newAlbum => console.log(newAlbum)) | ||
// .catch(err => console.log(err)); | ||
|
||
|
||
// request.put("https://jsonplaceholder.typicode.com/albums/10",{userId:10,title:"Tarkan Karma"}) | ||
// .then(album => console.log(album)) | ||
// .catch(err => console.log(err)); | ||
|
||
|
||
|
||
// request.delete("https://jsonplaceholder.typicode.com/albums/1") | ||
// .then(message => console.log(message) ) | ||
// .catch(err => console.log(err)); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
13 changes: 13 additions & 0 deletions
13
Asenkron Programlama - ES6 , Promise, Fetch/Fetch - Get Request/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Fetch - Get Request</title> | ||
</head> | ||
<body> | ||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> |
30 changes: 30 additions & 0 deletions
30
Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function getTextFile(){ // Text Dosyası | ||
|
||
fetch("example.txt") | ||
.then(response => response.text()) | ||
.then(data => console.log(data)) | ||
.catch(err => console.log(err)); | ||
|
||
} | ||
function getJsonFile(){ // Local bir Json Dosyasından Veri Alma | ||
|
||
fetch("example.json") | ||
.then(response => response.json()) | ||
.then(data => console.log(data)) | ||
.catch(err => console.log(err)); | ||
} | ||
function getExternalAPI(){ | ||
fetch("https://api.exchangeratesapi.io/latest") | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log(data.rates.TRY); | ||
}) | ||
.catch(err => console.log(err)); | ||
} | ||
// getTextFile(); | ||
// getJsonFile(); | ||
// getExternalAPI(); | ||
|
||
// https://api.exchangeratesapi.io/latest | ||
|
||
|
17 changes: 17 additions & 0 deletions
17
Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/example.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"name":"Mustafa", | ||
"age" :25, | ||
"salary":4000 | ||
}, | ||
{ | ||
"name":"Oğuz", | ||
"age" :25, | ||
"salary":5000 | ||
}, | ||
{ | ||
"name":"Serhat", | ||
"age" :26, | ||
"salary":3500 | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/example.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Burası bir text dosyası |
15 changes: 15 additions & 0 deletions
15
Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>FETCH</title> | ||
</head> | ||
<body> | ||
|
||
|
||
<script src="app.js"></script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.