Skip to content

[routes-d] GET /api/routes-d/exchange-rate — get USDC to NGN exchange rate #346

@davedumto

Description

@davedumto

Overview

Implement a `GET` handler that returns the current USDC to NGN exchange rate by calling the existing exchange rate utility in the codebase.

⚠️ Scope: Write your code only inside `app/api/routes-d/exchange-rate/route.ts`. Do not wire this into any page, component, or existing route.


Create the route file

File: `app/api/routes-d/exchange-rate/route.ts`

Note: The existing `app/api/exchange-rate/` route handles this for the main app. Do NOT modify that file. Write a fresh, standalone handler in the `routes-d` folder only.

Handler logic

  1. No auth required — exchange rate is public data
  2. Check the existing `app/api/exchange-rate/route.ts` to understand how the rate is fetched in this codebase, then replicate the same approach in your file
  3. Return the rate along with a timestamp

Expected response

```json
{
"rate": {
"from": "USDC",
"to": "NGN",
"value": 1620.50,
"fetchedAt": "2025-01-01T12:00:00.000Z"
}
}
```

Error handling

If the upstream rate fetch fails, return:

```json
{ "error": "Unable to fetch exchange rate" }
```

Status: `503 Service Unavailable`


Acceptance criteria

  • Returns `200` with rate object including `fetchedAt` timestamp
  • No authentication required
  • Returns `503` with descriptive error if upstream rate source is unavailable
  • `value` is a number, not a string

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions