Skip to main content
GET
/
api
/
images
List Images
curl --request GET \
  --url https://api.example.com/api/images
{
  "images": [
    {
      "id": 123,
      "name": "<string>"
    }
  ]
}
Retrieve a list of all cat images stored in the Cat Data API. This endpoint returns metadata for all images, including their IDs and filenames.

Authentication

This endpoint requires Auth0 JWT authentication. Include the JWT token in the Authorization header:
Authorization: Bearer <your-token>

Request

This endpoint does not require any parameters or request body.

Response

Returns an array of image objects.
images
array
An array of image objects. Each object contains:
id
number
The unique identifier for the image.
name
string
The filename under which the image is stored on the server (includes UUID prefix).

Success Response (200)

[
  {
    "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"
  }
]

Empty List Response

If no images have been uploaded yet, the endpoint returns an empty array:
[]

Error Responses

401 Unauthorized

Returned when the JWT token is missing or invalid.
{
  "error": "Unauthorized"
}

Example Requests

cURL

curl -X GET https://api.example.com/api/images \
  -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."

JavaScript Fetch

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}`);
    });
  });

Python Requests

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']}")

Implementation Details

The endpoint:
  1. Authenticates the request using the checkJwt middleware
  2. Calls the getAllImages() database function
  3. Returns the array of image objects as JSON
The actual implementation from src/index.ts:76-80:
app.get('/api/images', checkJwt, async (req, res) => {
  const images = await getAllImages();
  res.json(images);
});
The database function from src/db-functions.ts:28-30:
export async function getAllImages(): Promise<{ id: number; name: string }[]> {
  return db('images').select('id', 'name');
}

Use Cases

  • Display a gallery of all uploaded cat images
  • Build a file picker/selector interface
  • Audit or inventory uploaded images
  • Populate dropdown menus with available images
  • Generate reports on stored images

Build docs developers (and LLMs) love