This service accepts a search string as a parameter and will return a set of images relating to the given search string. The JSON response includes the image's URL, alt text, thumbnail link, and context link. You can also get a list of the most recently submitted search strings.
You can test it at https://img-search-layer-microsrvc.herokuapp.com
A Full Stack Javascript application built using MongoDB, Node.js and Express. An API Project for FreeCodeCamp.
To retrieve a set of images, pass a search term to path https://img-search-layer-microsrvc.herokuapp.com/api/imagesearch/[SEARCHTERM]
You can also paginate through the responses by adding a ? offset=[number] parameter to the URL path.
https://img-search-layer-microsrvc.herokuapp.com/api/imagesearch/puppies
https://img-search-layer-microsrvc.herokuapp.com/api/imagesearch/puppies?offset=2
[
{
url: "https://www.dogliciousspa.com/v/vspfiles/assets/images/puppiesplaying.jpg",
alt_text: "Puppy Socialization, Puppy Class, Training, Dogs, Dog Training ...",
thumbnailLink: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSwKw73Q78qFF4WA8BrYpA6T_C0cZgd6yvM6QNjQhzJMHrW02vu0UxMjt5h",
contextLink: "https://www.dogliciousspa.com/category-s/171.htm"
},
{
url: "https://i.ytimg.com/vi/2Y1ZyjGdPeE/maxresdefault.jpg",
alt_text: "Puppies Talking and Arguing With Their Humans Compilation - YouTube",
thumbnailLink: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSAoM6k7NCjsTVjuvRXTelL7s8XEI0LNicjVZPz4Wy2FkdFMbPJ7xHX5W8",
contextLink: "https://www.youtube.com/watch?v=2Y1ZyjGdPeE"
},
.
.
.
]
Make a request to:
https://img-search-layer-microsrvc.herokuapp.com/api/recent
In order to run this project locally, you should have the following installed:
You should also:
-
Create a Google Custom Search Engine https://cse.google.com/cse: Do not specify any sites to search but instead use the "Restrict Pages using Schema.org Types" under the "Advanced options". For the most inclusive set, use the Schema: Thing. In your search engine settings, enable "Image search". Make a note of the CSE ID.
-
Set up a Google Custom Search Engine API: Register a new app and enable Google Custom Search Engine API Google Developers Console. Make a note of the API key.
-
Fork this repo
-
Clone the fork
-
Install Dependencies:
$ npm install
-
Run your MongoDB server:
$ mongod --port 27017 --dbpath=./data
Note: Your mongoDB is now running at: mongodb://localhost:27017/<your_database_name>
-
Add a .env file to your project's root directory and set MONGO_CONNECTION_STRING to mongodb://localhost:27017/<your_database_name>
MONGO_CONNECTION_STRING=mongodb://localhost:27017/<your_database_name>
-
You wil also need the CSE ID and your Google CSE API Keys in your .env file and name them CSE_ID and CSE_API_KEY, respectively
CSE_ID=<your_cse_id> CSE_API_KEY=<your_google_cse_api_key>
-
Start the Server:
$ node app.js
-
Visit http://localhost:3000/
Enjoy! 💙