PHP rest wrapper for api endpoint with query

776

I have an api that I can test at it's current endpoint with a query (this is for a search with autocomplete) like so:

.../search/autocomplete?query=product123

And this returns the results expected. However, this is the first time I've made a php rest/wrapper for an api using a query instead of fields.

My question is, using a hard coded test variable below, How should I properly pass this into the function and properly query the endpoint?

This is a test but basically it's going to be used as someone types into a search box and passes from there, so same idea.

Am I on the right track with this?

$testVariable = "product123"

public function getSearch($testVariable)
    {
        return $this->get("/search/autocomplete?query={$testVariable}");
    }

People are also looking for solutions to the problem: php - Make a curl request to a url having no file extension?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.