const searchMovies=async(title)=>{
const response =await fetch(`${API_URL}&s=${title}`)
const data = await response.json();
setMovies(data.Search)
}
what is &s inside the api call? what does it do?
tried googling for answers but couldnt find any
2
Answers
The
&
sign is a separator for query parameters in an URL.In your sample
s
is a query parameter. But maybe theAPI_URL
already contains other query parameters, because before the first parameter usually has to be a?
sign like in this URL of a google search:https://www.google.com/search?client=firefox-b-d&q=test
whereclient
is the first parameter (with the valuefirefox-b-d
) andq
is the second (with the valuetest
).It’s part of a query-string which is a component of a universal resource locator (URL), and it is used to separate multiple queries. See parameters.
If you want to work with query strings in JS, try the URLSearchParams interface, which is part of the web API