-
Notifications
You must be signed in to change notification settings - Fork 89
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
44c094b
commit fa0b705
Showing
7 changed files
with
197 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,20 @@ | ||
# Bing Search API App | ||
|
||
This is a simple web application that integrates with the Bing Search API to perform web searches with a minimalist design. | ||
|
||
## Files | ||
|
||
- `index.html`: The main HTML file that structures the app. | ||
- `index.js`: The JavaScript file that handles the search functionality with the Bing Search API. | ||
- `styles.css`: The CSS file for styling the app. | ||
- `manifest.json`: Configuration for Progressive Web App (PWA) features. | ||
- `package.json`: Contains metadata about the project and its dependencies. | ||
|
||
## How to Use | ||
|
||
1. **Obtain a Bing Search API Key**: | ||
- Sign up for an Azure account and create a Bing Search resource to get your API key. | ||
|
||
2. **Clone the Repository**: | ||
```bash | ||
git clone <repository-url> |
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,24 @@ | ||
|
||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Bing Search API App</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Bing Search API App</h1> | ||
</header> | ||
<main> | ||
<form id="search-form"> | ||
<input type="text" id="search-input" placeholder="Search..."> | ||
<button type="submit">Search</button> | ||
</form> | ||
<div id="results"></div> | ||
</main> | ||
<script src="index.js"></script> | ||
</body> | ||
</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,41 @@ | ||
const apiKey = 'YOUR_BING_SEARCH_API_KEY'; // Replace with your Bing Search API key | ||
const endpoint = 'https://api.bing.microsoft.com/v7.0/search'; | ||
|
||
document.getElementById('search-form').addEventListener('submit', function(event) { | ||
event.preventDefault(); | ||
const query = document.getElementById('search-input').value; | ||
if (query) { | ||
fetch(`${endpoint}?q=${encodeURIComponent(query)}`, { | ||
method: 'GET', | ||
headers: { | ||
'Ocp-Apim-Subscription-Key': apiKey | ||
} | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
const resultsContainer = document.getElementById('results'); | ||
resultsContainer.innerHTML = ''; | ||
if (data.webPages && data.webPages.value.length > 0) { | ||
const results = data.webPages.value.map(page => ` | ||
<div class="result-item"> | ||
<h2><a href="${page.url}" target="_blank">${page.name}</a></h2> | ||
<p>${page.snippet}</p> | ||
</div> | ||
`).join(''); | ||
resultsContainer.innerHTML = `<h3>Results:</h3>${results}`; | ||
} else { | ||
resultsContainer.innerHTML = '<p>No results found.</p>'; | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching search results:', error); | ||
const resultsContainer = document.getElementById('results'); | ||
resultsContainer.innerHTML = '<p>An error occurred while fetching search results.</p>'; | ||
}); | ||
} | ||
}); |
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,20 @@ | ||
{ | ||
"name": "Bing Search API App", | ||
"short_name": "Bing Search App", | ||
"start_url": "/", | ||
"display": "standalone", | ||
"background_color": "#ffffff", | ||
"theme_color": "#000000", | ||
"icons": [ | ||
{ | ||
"src": "icons/icon-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "icons/icon-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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": "bing-search-api-app", | ||
"version": "1.0.0", | ||
"description": "A simple web app that integrates with Bing Search API for web search functionality.", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "echo 'No start script defined'" | ||
}, | ||
"keywords": [ | ||
"search", | ||
"bing", | ||
"api", | ||
"web" | ||
], | ||
"author": "Amrutha", | ||
"license": "MIT" | ||
} |
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,62 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f5f5f5; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
header { | ||
background-color: #000; | ||
color: #fff; | ||
width: 100%; | ||
text-align: center; | ||
padding: 10px; | ||
} | ||
|
||
main { | ||
margin-top: 20px; | ||
width: 80%; | ||
max-width: 800px; | ||
} | ||
|
||
#search-form { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
#search-input { | ||
width: 300px; | ||
padding: 10px; | ||
margin-right: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
border: none; | ||
background-color: #007bff; | ||
color: #fff; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
.result-item { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.result-item h2 a { | ||
text-decoration: none; | ||
color: #007bff; | ||
} | ||
|
||
.result-item h2 a:hover { | ||
text-decoration: underline; | ||
} |