Skip to content

Commit

Permalink
Dosyalar Yüklendi
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafamuratcoskun committed Oct 24, 2018
1 parent 4c91bc0 commit ef1e38d
Show file tree
Hide file tree
Showing 179 changed files with 24,661 additions and 0 deletions.
157 changes: 157 additions & 0 deletions Ajax - HTTP Requests/app.js
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);
}

});
14 changes: 14 additions & 0 deletions Ajax - HTTP Requests/index.html
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>
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));







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 Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/app.js
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 Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/example.json
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
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Burası bir text dosyası
15 changes: 15 additions & 0 deletions Asenkron Programlama - ES6 , Promise, Fetch/Fetch API/index.html
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>
Loading

0 comments on commit ef1e38d

Please sign in to comment.