Request Information
Get details about your request headers, IP address, and user agent.
cURL
JavaScript
Python
curl -X GET "https://mockly.me/headers"
fetch('https://mockly.me/headers')
.then(response => response.json())
.then(data => {
console.log('Request headers:', data.headers);
// Display headers in your application
const headersList = document.getElementById('headers-list');
Object.entries(data.headers).forEach(([key, value]) => {
const listItem = document.createElement('li');
listItem.textContent = `${key}: ${value}`;
headersList.appendChild(listItem);
});
});
import requests
# Get request headers
response = requests.get('https://mockly.me/headers')
data = response.json()
print("Your request headers:")
for header, value in data['headers'].items():
print(f"{header}: {value}")
Result Preview:
{
"headers": {
"host": "mockly.me",
"connection": "keep-alive",
"sec-ch-ua": "\"Chromium\";v=\"112\"",
"sec-ch-ua-mobile": "?0",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"sec-ch-ua-platform": "\"Windows\"",
"accept": "*/*",
"sec-fetch-site": "same-origin",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "https://mockly.me/docs",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9"
}
}
cURL
JavaScript
Python
curl -X GET "https://mockly.me/ip"
// Get client IP address
fetch('https://mockly.me/ip')
.then(response => response.json())
.then(data => {
console.log('Your IP address:', data.ip);
console.log('Forwarded for:', data.forwarded_for);
// Display IP in your application
document.getElementById('client-ip').textContent = data.ip;
});
import requests
# Get client IP address
response = requests.get('https://mockly.me/ip')
data = response.json()
print(f"Your IP address: {data['ip']}")
if data['forwarded_for']:
print(f"X-Forwarded-For: {data['forwarded_for']}")
Result Preview:
{
"ip": "203.0.113.195",
"forwarded_for": "203.0.113.195"
}
cURL
JavaScript
Python
curl -X GET "https://mockly.me/user-agent"
// Get user agent information
fetch('https://mockly.me/user-agent')
.then(response => response.json())
.then(data => {
console.log('Your user agent:', data.user_agent);
// Display user agent in your application
document.getElementById('user-agent').textContent = data.user_agent;
// You can parse the user agent for browser detection
const isMobile = /Mobile|Android|iPhone|iPad|iPod/i.test(data.user_agent);
if (isMobile) {
document.getElementById('device-type').textContent = 'Mobile Device';
} else {
document.getElementById('device-type').textContent = 'Desktop Device';
}
});
import requests
import re
# Get user agent information
response = requests.get('https://mockly.me/user-agent')
data = response.json()
user_agent = data['user_agent']
print(f"User Agent: {user_agent}")
# Simple browser detection example
if re.search(r'Chrome', user_agent):
print("Browser: Chrome")
elif re.search(r'Firefox', user_agent):
print("Browser: Firefox")
elif re.search(r'Safari', user_agent) and not re.search(r'Chrome', user_agent):
print("Browser: Safari")
elif re.search(r'MSIE|Trident', user_agent):
print("Browser: Internet Explorer")
else:
print("Browser: Unknown")
Result Preview:
{
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
}
Echo
Echo back your request parameters, body, and headers.
cURL
JavaScript
Python
# GET request with query parameters
curl -X GET "https://mockly.me/echo?name=John&age=30"
# POST request with JSON body
curl -X POST "https://mockly.me/echo" \
-H "Content-Type: application/json" \
-d '{"name": "John", "age": 30, "interests": ["coding", "hiking"]}'
// Echo back GET request with query parameters
fetch('https://mockly.me/echo?name=John&age=30')
.then(response => response.json())
.then(data => {
console.log('Echo response (GET):', data);
});
// Echo back POST request with JSON body
fetch('https://mockly.me/echo', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'John',
age: 30,
interests: ['coding', 'hiking'],
metadata: {
source: 'web',
timestamp: Date.now()
}
})
})
.then(response => response.json())
.then(data => {
console.log('Echo response (POST):', data);
// Display the echoed data
document.getElementById('echo-result').textContent =
JSON.stringify(data, null, 2);
});
import requests
import json
# GET request with query parameters
params = {'name': 'John', 'age': 30, 'city': 'New York'}
response = requests.get('https://mockly.me/echo', params=params)
echo_data = response.json()
print("Echo response (GET):")
print(json.dumps(echo_data, indent=2))
# POST request with JSON body
payload = {
'name': 'John',
'age': 30,
'interests': ['coding', 'hiking'],
'address': {
'street': '123 Main St',
'city': 'New York',
'zipcode': '10001'
}
}
response = requests.post('https://mockly.me/echo', json=payload)
echo_data = response.json()
print("\nEcho response (POST):")
print(json.dumps(echo_data, indent=2))
Result Preview (GET request):
{
"method": "GET",
"params": {
"name": "John",
"age": "30"
},
"body": null,
"headers": {
"host": "mockly.me",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"referer": "https://mockly.me/docs"
}
}
Redirect
Generate URL redirects for testing.
cURL
JavaScript
Python
# Redirect to example.com
curl -L "https://mockly.me/redirect/example.com"
# Redirect to a full URL
curl -L "https://mockly.me/redirect/https://github.com"
// Create a redirect button
document.getElementById('redirect-button').addEventListener('click', () => {
const targetUrl = document.getElementById('redirect-target').value;
const redirectUrl = `https://mockly.me/redirect/${encodeURIComponent(targetUrl)}`;
// Show the user where they're being redirected
alert(`You will be redirected to: ${targetUrl}`);
// Perform the redirect
window.location.href = redirectUrl;
});
import requests
# Test redirect with different options
url = "example.com" # Domain without protocol
redirect_url = f"https://mockly.me/redirect/{url}"
# Allow redirects (default behavior)
response = requests.get(redirect_url, allow_redirects=True)
print(f"Followed redirect to: {response.url}")
print(f"Final status code: {response.status_code}")
# Disable redirects to inspect the redirect response
response = requests.get(redirect_url, allow_redirects=False)
print(f"Redirect status code: {response.status_code}")
if 'Location' in response.headers:
print(f"Redirect location: {response.headers['Location']}")
Behavior:
HTTP/1.1 307 Temporary Redirect
Location: https://example.com
AI-Powered
Meet Mockly Assistant
Your AI assistant for API testing, debugging and code generation. Access the power of mockly.me directly in ChatGPT.
- Generate code examples in your preferred language
- Get guidance for request/response handling and formatting
- Supercharged by ChatGPT Plus from OpenAI
"How do I send data to a POST endpoint"
"I can show you how to structure your request with headers and JSON — here's a code example..."
Powered by AI