0

I'm starting to learn about axios endpoints, and I was wondering why would we use query parameters for an endpoint?

Google states we use it as it "helps to retrieve specific data and performs actions based on the inputs passed by the user"

I believe there is a "filter" function we can use to filter the responses and I assumed we could use query parameters to do something similar, but I'm not sure if that's what they meant. I created a client and server example where I passed query parameters to the server and it returned a response with the parameters I sent. This makes sense, but what is the point?

webdesignnoob
  • 381
  • 1
  • 4
  • 13

1 Answers1

1

Query parameters are used to target more specific queries. Imagine if you were ordering items from an e-commerce website.

By putting search parameters in the url, it will allow us to filter out our exact requests in order to grab the data that we want.

Here's another Stack answer that may be helpful! https://stackoverflow.com/a/25405668/15492085

DOZBORNE
  • 560
  • 3
  • 13
  • @DOZCORNE Ah I see. To clarify, if I sent the query param to be Name: 'Bob', then on the server side, I would be able to take that param and use it to find responses that have the Name = 'Bob', then send those back to the client? In other words, I would have to do something with the query params? My previous understanding is that it would automatically filter things for me. – webdesignnoob Jan 15 '22 at 09:37
  • 1
    Right, so technically, you can access the query params on the server just as you could access the body of a `POST` request. It's quite simple to do actually. From there, you could use that data, let's say it's a name "Bob" and you could insert that into a SQL script to then pull the User with the name "Bob". – DOZBORNE Jan 15 '22 at 09:43
  • 1
    It can filter, but that would be solely used on the front end client-side of things, like used with something like react router. It can further pass query values down to filter your data from data you've already fetched, or fetch it. https://medium.com/@chris.luu/easy-query-params-in-reactjs-e9a88ffad4bb – DOZBORNE Jan 15 '22 at 09:43