cURL
curl --request GET \ --url https://api.example.com/api/images
{ "images": [ { "id": 123, "name": "<string>" } ] }
Authorization: Bearer <your-token>
[ { "id": 1, "name": "a1b2c3d4-e5f6-7890-abcd-ef1234567890-cat1.jpg" }, { "id": 2, "name": "b2c3d4e5-f6g7-8901-bcde-fg2345678901-cat2.png" }, { "id": 3, "name": "c3d4e5f6-g7h8-9012-cdef-gh3456789012-cat3.jpg" } ]
[]
{ "error": "Unauthorized" }
curl -X GET https://api.example.com/api/images \ -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
fetch('https://api.example.com/api/images', { headers: { 'Authorization': `Bearer ${token}` } }) .then(response => response.json()) .then(images => { console.log(`Found ${images.length} images`); images.forEach(image => { console.log(`ID: ${image.id}, Name: ${image.name}`); }); });
import requests headers = { 'Authorization': f'Bearer {token}' } response = requests.get('https://api.example.com/api/images', headers=headers) images = response.json() for image in images: print(f"ID: {image['id']}, Name: {image['name']}")
getAllImages()
app.get('/api/images', checkJwt, async (req, res) => { const images = await getAllImages(); res.json(images); });
export async function getAllImages(): Promise<{ id: number; name: string }[]> { return db('images').select('id', 'name'); }