Created
January 10, 2022 10:03
-
-
Save pacwoodson/d65d077c057681c992d495761f5263c7 to your computer and use it in GitHub Desktop.
Fetch coingecko prices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | |
async function getPrice(ids: string, vs: string) { | |
const url = | |
`https://api.coingecko.com/api/v3/simple/price?ids=${ids}&vs_currencies=${vs}`; | |
const res = await fetch(url); | |
const body = res.json(); | |
return body; | |
} | |
async function handler(req: Request): Promise<Response> { | |
const url = new URL(req.url); | |
const ids = url.searchParams.get("ids") || "bitcoin"; | |
const vs = url.searchParams.get("vs") || "usd"; | |
const res = await getPrice(ids, vs); | |
return new Response(JSON.stringify(res)); | |
} | |
serve(handler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment