Nodejs
Nodejs
GET: To get a representation of a resource, use this method.
POST: To generate fresh resources
PUT: Used to update capabilities
PATCH : Used to modify capabilities
DELETE: To remove a resource indicated by a URL, use this command.
OPTIONS: For a particular URL or server, request an allowed communication option.
axios.get('https://example.com')
.then(response => {console.log(response.data)})
.catch(error => {console.log(error)})
Dependency array
πΉππ π ππππππ
Axios.get
Faizan Imran - 29/10/2024
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Axios GET Request Example</title>
<!-- Add some CSS to style the output -->
<style>
#data {
margin-top: 20px;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Axios GET Request Example</h1>
<div id="data">Loading data...</div>
<!-- Include Axios from CDN -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// Make an axios GET request
axios.get('https://jsonplaceholder.typicode.com/posts/1')
.then(response => {
// Display the data in the "data" div
document.getElementById('data').innerText = JSON.stringify(response.data, null, 2);
})
.catch(error => {
// Handle any errors
document.getElementById('data').innerText = 'Error loading data';
console.error(error);
});
</script>
</body>
</html>
Comments
Post a Comment