javascript
// JavaScript - URLSearchParams
const params = new URLSearchParams();
params.append('page', '1');
params.append('limit', '10');
const url = 'https://api.example.com/endpoint?' + params.toString();
console.log(url);
// JavaScript - Fetch API
fetch(url)
.then(response => response.json())
.then(data => console.log(data));
python
# Python - requests library
import requests
params = {
'page': '1',
'limit': '10',
}
response = requests.get('https://api.example.com/endpoint', params=params)
print(response.url)
print(response.json())
curl
# cURL command
curl -X GET "" \
-H "Accept: application/json"
php
<?php
// PHP - using http_build_query
$params = [
'page' => '1',
'limit' => '10',
];
$url = 'https://api.example.com/endpoint?' . http_build_query($params);
echo $url;
// Using cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);