Last active
May 8, 2019 14:12
-
-
Save tclain/7d22bd8d66fa06c393810370c850fbaa to your computer and use it in GitHub Desktop.
algolia fetch
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
const ALGOLIA_PLACES = "https://places-dsn.algolia.net/1/places/query" | |
//const searchBody = (query) => `{"params":"hitsPerPage=5&language=en&query=${query}"}` | |
const searchBody = (query) => { | |
return JSON.stringify({ | |
"params":`hitsPerPage=5&language=en&query=${query}` | |
}) | |
} | |
const searchBox = document.querySelector("#search") | |
searchBox.addEventListener('input', (event) => { | |
const value = event.currentTarget.value; | |
fetch(ALGOLIA_PLACES, { | |
method: "POST", | |
body: searchBody(value) | |
}) | |
.then((response) => response.json()) | |
.then((json) => { | |
console.log(json) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment