hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT]: Implement Endpoint to fetch an image #261

Closed Samilincoln closed 2 weeks ago

Samilincoln commented 1 month ago

Description

Creating an API endpoint for getting an image by slug, with resizing and caching.

Acceptance Criteria

  1. Read Image
    • Users can fetch an image.
    • Appropriate error messages for not found or unauthorized requests.
    • Image resixing functionality.
    • Caching

Purpose

The purpose of this project is to allow users to access an image through a well-defined API.

Requirements

Read Images

Expected Outcome

Users should be able to get an image through a secure API with optional resizing, caching and appropriate responses.

API Endpoint

Request with resizing

GET /v1/api/images/image-slug?width=300&height=300 HTTP/1.1
Host: example.com
Authorization: Bearer <token>

Request without resizing

GET /v1/api/images/image-slug HTTP/1.1
Host: example.com
Authorization: Bearer <token>

Response body (success)

{
    "slug": "image-slug",
    "url": "https://example.com/image1.jpg",
    "description": "Sample image 1",
    "timestamp": "2024-07-17T12:00:00Z"
}

Response body (error)

{
  "error": "Not Found",
  "message": "Image with the given slug not found."
},
{
  "error": "Unauthorized",
  "message": "Authentication token is missing or invalid."
}

Tasks

Testing

Test GET /v1/api/images/

markessien commented 1 month ago

duplicat