Get currentSite.handle in Element API I need to get the currentSite in Element API. How can this be achieved? Is it as a slug in the endpoint URL? or as a Query param? Here is the current code:
&lt;?php

use craft\elements\Entry;
use craft\helpers\UrlHelper;
use craft\services\Sites;

return [
    'defaults' =&gt; [
        'resourceKey' =&gt; 'suggestions',
        'cache' =&gt; false,
        'paginate' =&gt; false,
        'pretty' =&gt; true,
    ],
    'endpoints' =&gt; [
        'api/search.json' =&gt; function() {

        $searchQuery = Craft::$app-&gt;request-&gt;getQueryParam('query');
        $site = Craft::$app-&gt;request-&gt;getQueryParam('site');

        $sectionHandles = [
            'pages',
            'news',
        ];

        // Search criterias
        $criteria = [
            'section' =&gt; $sectionHandles,
            'search' =&gt; $searchQuery,
            'site' =&gt; $site,
            'orderBy' =&gt; 'score',
            'limit' =&gt; 10,
        ];

            return [
                'elementType' =&gt; Entry::class,
                'criteria' =&gt; $criteria,
                'paginate' =&gt; false,

            'transformer' =&gt; function(craft\elements\Entry $entry) {

                return [
                    'title' =&gt; $entry-&gt;title,
                    'url' =&gt; $entry-&gt;url,
                ];
            },

            ];
        },
    ]
];
The currentSite property from the Sites service is what you're looking for. Here's how you would use it:
'api/search.json' =&gt; function() {

    $siteHandle = Craft::$app-&gt;getSites()-&gt;currentSite-&gt;handle;

    ...

    $criteria = [
        'site' =&gt; $siteHandle,
        ...
    ];

    return [
        ...
    ];
},