Skip to content
Permalink
Browse files

setup a fetch request to pull in json & log to console

  • Loading branch information...
equk committed Jul 31, 2018
1 parent 40692d7 commit 3b4106e9a260fb6cb57ddb66a2b854ba5529c009
Showing with 25 additions and 1 deletion.
  1. +6 −0 public/css/app.css
  2. +19 −1 public/js/app.js
@@ -177,3 +177,9 @@ input#searchTerm.searchBox {
form {
padding-bottom: 1em;
}

.createdby {
position: absolute;
top:1em;
right:1em;
}
@@ -1,5 +1,23 @@
const API_CLIENTID = '-insert-your-api-key-'
const API_CLIENTID = ''
const form = document.querySelector('form');
const input = document.querySelector('input');
const imageSection = document.querySelector('.images');
const API_URL = `https://api.unsplash.com/search/photos?page=1&per_page=20&client_id=${API_CLIENTID}`

form.addEventListener('submit', formSubmitted);

function formSubmitted(event) {
event.preventDefault();
let searchTerm = input.value;

search(searchTerm)
}

function search(searchTerm) {
let url = `${API_URL}&query=${searchTerm}`;
return fetch(url)
.then(response => response.json())
.then(result => {
console.log(result.results);
});
}

0 comments on commit 3b4106e

Please sign in to comment.
You can’t perform that action at this time.