frontend āĻ āĻāĻŽāϰāĻž designe āĻāϰ⧠āĻĨāĻžāĻāĻŋ āĻāϰ backend/āϏāĻžāϰā§āĻāĻžāϰ āĻ āĻāĻŽāϰāĻž āĻŦāĻŋāĻāĻŋāύā§āύ āϰāĻāĻŽ āϞāĻāĻŋāĻ āϞāĻŋāĻā§ āĻĨāĻžāĻāĻŋ āĻāϰ āĻāĻ āϞāĻāĻŋāĻ āĻāϞ⧠āĻĻāĻŋā§ā§ āĻāĻŽāϰāĻž database āĻā§āϞ⧠āĻšā§āϝāĻžāύā§āĻĄā§āϞ āĻāϰ⧠āĻĨāĻžāĻāĻŋ
suppose āĻāĻĒāύāĻŋ frontend āĻ āĻāĻžāĻ āĻāϰāĻā§āύ āĻāϰ āĻāĻĒāύāĻžāϰ data āϞāĻžāĻāĻŦā§ āĨ¤ āϤāĻžāĻšāϞ⧠data āĻā§āϞ⧠āĻāĻĒāύāĻŋ āĻāĻŋāĻāĻžāĻŦā§ āĻĒāĻžāĻŦā§āύ āĨ¤ āĻāĻŽāϰāĻž āĻāĻžāύāĻŋ data āĻā§āϞ⧠database āĻ āϰā§ā§āĻā§ āĻāϰ database āĻā§ handle āĻāϰāĻā§ āĻŽā§āϞāϤ āϏāĻžāϰā§āĻāĻžāϰ āĨ¤ āĻāϰ āĻŽāĻžāύ⧠frontend āĻĨā§āĻā§ server āĻ call āĻĻāĻŋāϤ⧠āĻšāĻŦā§ data āĻĒāĻžāĻā§āĻžāϰ āĻāύā§āϝ⧠āĨ¤ āϏā§āĻāĻž āĻšāϤ⧠āĻĒāĻžāϰ⧠database āĻĨā§āĻā§ data āĻĒāĻžāĻā§āĻžāϰ āĻāύā§āϝ⧠āĻšāϤ⧠āĻĒāĻžāϰ⧠database āĻ data update āĻāϰāϤ⧠āĻ āĻĨāĻŦāĻž frontend āĻĨā§āĻā§ āύā§āϤāύ data send āĻāϰāϤ⧠āĻāĻžāĻāĻāĻŋ āĻāĻŋāĻāĻŦāĻž data delete āĻāϰāϤ⧠āĻāĻžāĻāĻāĻŋ
āĻāĻ āĻŦāĻŋāĻāĻŋāύā§āύ āϧāϰāύā§āϰ request āĻāĻŽāϰāĻž frontend āĻĨā§āĻā§ server āĻ send āĻāϰāϤ⧠āĻāĻžāĻāĻāĻŋ āĨ¤ āϏā§āĻ āĻāύā§āϝ⧠āĻāĻŽāĻžāϰ āĻāĻāĻāĻž āϞāĻŋāĻāĻ āϞāĻžāĻāĻŦā§ āĨ¤ āϏā§āĻ āϞāĻŋāĻāĻ āĻāĻž āĻšāĻā§āĻā§ api
server āϝāĻāύ āϤā§āϰāĻŋ āĻāϰāĻž āĻšā§ āϤāĻāύ āĻāĻ api āĻā§āϞ⧠āϤā§āϰāĻŋ āĻāϰāĻž āĻšā§ āĨ¤ āĻāĻ āĻāύā§āϝ⧠āϝāĻžāϤ⧠frontend āĻĨā§āĻā§ server āĻāϰ āĻŽāϧ⧠connection āĻāϰ āĻāύā§āϝ⧠āĻāĻ api āĻā§āϞ⧠āϤā§āϰāĻŋ āĻāϰāĻž āĻšā§
āϤāĻžāĻšāϞ⧠api āĻāϞ⧠āĻšāϞ āĻāĻāĻāĻž link āĻŦāĻž url āϝāĻžāϰ āĻŽāĻĻā§āϝāĻŽā§ āĻĢā§āϰāύā§āĻāĻāύā§āĻĄ āĻāϰ āϏāĻžāϤ⧠āĻŦāĻāĻā§āύā§āĻĄ āĻāϰ relation āĻāϰāϤ⧠āĻĒāϰāĻŋ āĻāĻŦāĻ āĻŦāĻŋāĻāĻŋāύā§āύ āϧāϰāĻŖā§ request āϏā§āύā§āĻĄ āĻāϰāϤ⧠āĻĒāĻžāϰāĻŋ āϏā§āĻ request āĻšāϤ⧠āĻĒāĻžāϰ⧠get ,put,fetch ,update ,patch,delete,post
APIs, short for Application Programming Interfaces, āϏāĻĢā§āĻāĻāϝāĻŧā§āϝāĻžāϰ āĻĨā§āĻā§ āϏāĻĢā§āĻāĻāϝāĻŧā§āϝāĻžāϰ āĻāύā§āĻāĻžāϰāĻĢā§āϏāĨ¤ Meaning, āϤāĻžāϰāĻž āĻŦāĻŋāĻāĻŋāύā§āύ āĻ ā§āϝāĻžāĻĒā§āϞāĻŋāĻā§āĻļāύāĻā§ āĻāĻā§ āĻ āĻĒāϰā§āϰ āϏāĻžāĻĨā§ āĻāĻĨāĻž āĻŦāϞāĻžāϰ āĻāĻŦāĻ āϤāĻĨā§āϝ āĻŦāĻž āĻāĻžāϰā§āϝāĻāĻžāϰāĻŋāϤāĻž āĻŦāĻŋāύāĻŋāĻŽāϝāĻŧ āĻāϰāĻžāϰ āĻ āύā§āĻŽāϤāĻŋ āĻĻā§āϝāĻŧāĨ¤
- XMLHttpRequest
- fetch
- axios
- jquery
- fetch() has replace XMLHttpRequest
- fetch() - global method for making HTTP request
- 2 way to call -than, async await
-
- fetch() is easy to use comapre to XMLHttpRequest
-
- fetch() returns a promise
-
- returned promise can only handle network error
-
- does not support all the older browser
is one old request .
console.log(window)const getData = function(){
const xhr = new XMLHttpRequest();
//i will get every property and method and event from creating new object of XMLHttpRequest
console.log(xhr);
}
getData();- event - onload(), onerror()
- property- response, responseType ,
- function - open() ,send() ,setRequestHeader()
const getData = function(){
const xhr = new XMLHttpRequest();
}
getData();
const getData = function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','URL')
}
getData();xmlHttpRequest() object āĻāϰ open() method call āĻāϰāĻŦ āĨ¤ open() method 2 āĻāĻž argument receive āĻāϰāĻŦā§ āĨ¤
const getData = function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','https://jsonplaceholder.typicode.com/posts/1')
}
getData();const getData = function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','https://jsonplaceholder.typicode.com/posts/1');
xhr.send();
}
getData();step - 6 (console e data āĻ data show āĻāϰāĻžāϰ āĻāύā§āϝ⧠onload event use āĻāϰāϤ⧠āĻšāĻŦā§ )
const getData = function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','https://jsonplaceholder.typicode.com/posts');
xhr.onload = function(){
let data = xhr.response;
console.log(data);
};
xhr.send();
}
getData();onload event āĻāϰ āĻŽāĻĻā§āϝ⧠data process āĻāϰāĻŦ āĨ¤ data āĻāĻž xhr.response property āĻāϰ āĻŽāĻĻā§āϝ⧠āϤāĻāĻŦā§ data =xhr.response console.log(data); āĻāϰ āĻĢāϞ⧠data console āĻ show āĻāϰāĻŦā§
const getData = function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','https://jsonplaceholder.typicode.com/posts');
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.send();
}
getData();const getData = function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','https://jsonplaceholder.typicode.como/posts');
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.onerror = function(){
console.log('error is here');
}
xhr.send();
}
getData();onerror event will find the error i change here https://jsonplaceholder.typicode.com/posts to https://jsonplaceholder.typicode.como/posts
onerror event will find the error
āĻāĻāĻžāĻŦā§ request make āĻāϰāϤ⧠āĻšā§ XMLHttpRequest() āĻāϰ āĻŽāĻĻā§āϝāĻŽā§
const makeRequest = function(method,url){
const xhr = new XMLHttpRequest();
xhr.open(method,url);
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.onerror = function(){
console.log('error is here');
}
xhr.send();
}
const getData = function(){
makeRequest('GET','https://jsonplaceholder.typicode.com/posts');
}
getData();method āĻšāĻŦā§ post url āĻšāĻŦā§
- title body userid āĻĻāĻŋāϤ⧠āĻšāĻŦā§
- open() āĻāĻŦāĻ send() function āĻāϰ āĻŽāĻžāĻā§ etRequestHeader('Content-type','application/json') āĻĻāĻŋāϤ⧠āĻšāĻŦā§
- data āĻā§ JSON.stringify(data1) āĻāϰāϤ⧠āĻšāĻŦā§
- send(JSON.stringify(data1))
const makeRequest = function(method,url,data1){
const xhr = new XMLHttpRequest();
xhr.open(method,url);
xhr.setRequestHeader('Content-type','application/json');
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.onerror = function(){
console.log('error is here');
}
xhr.send(JSON.stringify(data1));
}
const getData = function(){
makeRequest('GET','https://jsonplaceholder.typicode.com/posts');
}
const postData = function(){
makeRequest('POST','https://jsonplaceholder.typicode.com/posts',{
title: 'foo',
body: 'bar',
userId: 1,
});
}
postData();const makeRequest = function(method,url,data1){
const xhr = new XMLHttpRequest();
xhr.open(method,url);
xhr.setRequestHeader('Content-type','application/json');
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.onerror = function(){
console.log('error is here');
}
xhr.send(JSON.stringify(data1));
}
const getData = function(){
makeRequest('GET','https://jsonplaceholder.typicode.com/posts');
}
const postData = function(){
makeRequest('POST','https://jsonplaceholder.typicode.com/posts',{
title: 'foo',
body: 'bar',
userId: 1,
});
}
const updateData = function(){
makeRequest('PUT','https://jsonplaceholder.typicode.com/posts/1',{
id:1,
title: 'foota',
body: 'barto',
userId: 1,
});
}
updateData();const makeRequest = function(method,url,data1){
const xhr = new XMLHttpRequest();
xhr.open(method,url);
xhr.setRequestHeader('Content-type','application/json');
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.onerror = function(){
console.log('error is here');
}
xhr.send(JSON.stringify(data1));
}
//get data
const getData = function(){
makeRequest('GET','https://jsonplaceholder.typicode.com/posts');
}
// single data update
const updateSingleData = function(){
makeRequest('PATCH','https://jsonplaceholder.typicode.com/posts/2',{
title: 'foowa',
});
}
updateSingleData();const makeRequest = function(method,url,data1){
const xhr = new XMLHttpRequest();
xhr.open(method,url);
xhr.setRequestHeader('Content-type','application/json');
xhr.onload = function(){
let data = xhr.response;
console.log(JSON.parse(data));
};
xhr.onerror = function(){
console.log('error is here');
}
xhr.send(JSON.stringify(data1));
}
// delete
// single data update
const deleteData = function(){
makeRequest('DELETE','https://jsonplaceholder.typicode.com/posts/1');
}
deleteData();
- fetch() has replace XMLHttpRequest
- fetch() - global method for making HTTP request
- 2 way to call -than, async await
-
- fetch() is easy to use comapre to XMLHttpRequest
-
- fetch() returns a promise
-
- returned promise can only handle network error
-
- does not support all the older browser









