-1
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?

I tried Googling for answers but couldn't find any.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

The & sign is a separator for query parameters in a URL. In your sample s is a query parameter. But maybe the API_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 where client is the first parameter (with the value firefox-b-d) and q is the second (with the value test).

kzi
  • 186
  • 1
  • 8
  • yes thank you so much, I went and looked at the documentation of that API and it did ask for another parameter "s" which is the search parameter. Sorry for such a lame question haha. – Aries Ha Jul 16 '23 at 06:33
0

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

smac89
  • 39,374
  • 15
  • 132
  • 179