Skip to content

Commit

Permalink
Merge pull request #89 from haard18/changed_unsplash
Browse files Browse the repository at this point in the history
Changed unsplash folder into the existingAPI Folder
  • Loading branch information
dishamodi0910 authored May 15, 2024
2 parents ce16bf5 + fdf2af6 commit 3e64adc
Show file tree
Hide file tree
Showing 12 changed files with 1,066 additions and 0 deletions.
1 change: 1 addition & 0 deletions Existing_API_Collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
|[Giphy API](./GiphyAPI)|This API allows developers to integrate Giphy's vast library of GIFs into their own applications, websites, and services.|
|[PokeAPI](./PokeAPI/)| This API provides data regarding Pokemon and others related. |
|[Product Store API](./ProductStoreAPI/)| A Product Store API using NodeJS, ExpressJS, MongoDB and Mongoose |
|[Unsplash API](./unsplashApi/)| An API that enables users to retrieve high quality and copyright free Images from Unsplash and also get random Images |

1 change: 1 addition & 0 deletions Existing_API_Collection/unsplashApi/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UNSPLASH_ACCESS="YOUR_ACCESS"
2 changes: 2 additions & 0 deletions Existing_API_Collection/unsplashApi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
Binary file added Existing_API_Collection/unsplashApi/Keywords.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Existing_API_Collection/unsplashApi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Gallery</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Image Gallery</h1>

<form id="searchForm">
<input type="text" id="keywordInput" placeholder="Enter keyword">
<button type="submit">Search</button>
</form>

<button id="randomImageButton">
Get Me a Random Image
</button>

<div id="imageContainer"></div>

<script>
document.getElementById('searchForm').addEventListener('submit', async function(event) {
event.preventDefault();
const keyword = document.getElementById('keywordInput').value.trim();
if (keyword !== '') {
const response = await fetch(`http://localhost:3000/images/keywordImage?query=${encodeURIComponent(keyword)}`);
const images = await response.json();
displayImages(images);
}
});

document.getElementById('randomImageButton').addEventListener('click', async function() {
const response = await fetch('http://localhost:3000/images/randomImage');
const images = await response.json();
displayImages(images);
});

async function displayImages(images) {
const imageContainer = document.getElementById('imageContainer');
imageContainer.innerHTML = '';

images.forEach(imageUrl => {
const img = document.createElement('img');
img.src = imageUrl;
img.alt = 'Image';
imageContainer.appendChild(img);
});
}
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions Existing_API_Collection/unsplashApi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express');
const axios = require('axios');
const cors = require('cors');
const imageRouter = require('./routes/image')
const app = express();
app.use(cors());
app.use(express.json());
app.use('/images', imageRouter);
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Loading

0 comments on commit 3e64adc

Please sign in to comment.