Skip to content

Instantly share code, notes, and snippets.

@tclain
Last active May 8, 2019 14:12
Show Gist options
  • Save tclain/7d22bd8d66fa06c393810370c850fbaa to your computer and use it in GitHub Desktop.
Save tclain/7d22bd8d66fa06c393810370c850fbaa to your computer and use it in GitHub Desktop.
algolia fetch
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