<!DOCTYPE html>
<html>
<head>
<title>API Documentation with Code Examples</title>
</head>
<body>
<h1>User API Documentation</h1>
<p>This API allows you to manage users in your application.</p>
<h2>Authentication</h2>
<p>Include your API key in the Authorization header:</p>
<pre><code class="language-bash">curl -H "Authorization: Bearer YOUR_API_KEY" https://api.example.com/users</code></pre>
<h2>Get All Users</h2>
<p>Retrieve a list of all users:</p>
<h3>JavaScript Example</h3>
<pre><code class="language-javascript">
const response = await fetch('/api/users', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + apiKey,
'Content-Type': 'application/json'
}
});
const users = await response.json();
console.log(users);
</code></pre>
<h3>Python Example</h3>
<pre><code class="language-python">
import requests
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
response = requests.get('https://api.example.com/users', headers=headers)
users = response.json()
print(users)
</code></pre>
<h2>Create User</h2>
<p>Create a new user by sending a POST request:</p>
<pre><code class="language-javascript">
const newUser = {
name: 'John Doe',
email: 'john@example.com'
};
const response = await fetch('/api/users', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify(newUser)
});
const createdUser = await response.json();
</code></pre>
<h2>Configuration</h2>
<p>Configure your application with these environment variables:</p>
<pre><code class="language-bash">
# Environment configuration
API_KEY=your_secret_api_key_here
DATABASE_URL=postgresql://user:pass@localhost/db
REDIS_URL=redis://localhost:6379
</code></pre>
<h2>Example Response</h2>
<p>The API returns JSON responses in this format:</p>
<pre><code class="language-json">
{
"users": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2023-01-01T00:00:00Z"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"created_at": "2023-01-02T00:00:00Z"
}
],
"total": 2
}
</code></pre>
</body>
</html>