import { CodeTabs, CodeTab } from "docs-ui"

export const metadata = {
  title: `Examples of the Currency Module`,
}

# {metadata.title}

In this guide, you’ll find common examples of how you can use the Currency Module in your application.

## List Currencies

<CodeTabs groupId="app-type">
  <CodeTab label="Medusa API Router" value="medusa">

  ```ts
  import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
  import { ICurrencyModuleService } from "@medusajs/types"
  import { ModuleRegistrationName } from "@medusajs/modules-sdk"

  export async function GET(
    req: MedusaRequest,
    res: MedusaResponse
  ): Promise<void> {
    const currencyModuleService: ICurrencyModuleService =
      req.scope.resolve(ModuleRegistrationName.CURRENCY)

    res.json({
      currencies: await currencyModuleService.list(),
    })
  }
  ```

  </CodeTab>
  <CodeTab label="Next.js App Router" value="nextjs">

  ```ts
  import { NextResponse } from "next/server"

  import {
    initialize as initializeCurrencyModule,
  } from "@medusajs/currency"

  export async function GET(request: Request) {
    const currencyModuleService = await initializeCurrencyModule()

    return NextResponse.json({
      currencies: await currencyModuleService.list(),
    })
  }
  ```

  </CodeTab>
</CodeTabs>

---

## Retrieve a Currency by its ID

<CodeTabs groupId="app-type">
  <CodeTab label="Medusa API Router" value="medusa">

  ```ts
  import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
  import { ICurrencyModuleService } from "@medusajs/types"
  import { ModuleRegistrationName } from "@medusajs/modules-sdk"

  export async function GET(
    req: MedusaRequest,
    res: MedusaResponse
  ): Promise<void> {
    const currencyModuleService: ICurrencyModuleService =
      req.scope.resolve(ModuleRegistrationName.CURRENCY)

    const currency = await currencyModuleService.retrieve("usd")

    res.json({
      currency,
    })
  }
  ```

  </CodeTab>
  <CodeTab label="Next.js App Router" value="nextjs">

  ```ts
  import { NextResponse } from "next/server"

  import {
    initialize as initializeCurrencyModule,
  } from "@medusajs/currency"

  export async function GET(
    request: Request
  ) {
    const currencyModuleService = await initializeCurrencyModule()

    const currency = await currencyModuleService.retrieve("usd")

    return NextResponse.json({ currency })
  }
  ```

  </CodeTab>
</CodeTabs>

---

## More Examples

The [Currency Module interface reference](/references/currency) provides a reference to all the methods available for use with examples for each.
