summaryrefslogtreecommitdiff
path: root/ping/frontend/src/routes/stocksapi/quote/+server.ts
blob: 96619fc0a2f527511733cb757ef667dde777f710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import type { RequestHandler } from '@sveltejs/kit';
import yahooFinance from 'yahoo-finance2';

/**
 * Example request : GET /stocksapi/quote?query=AAPL
 */
export const GET: RequestHandler = async ({ request }) => {
    const sp = new URL(request.url).searchParams;
    const query = sp.get('query') || 'AAPL';

    const data = await yahooFinance.quote(query);
    return new Response(JSON.stringify(data), {
        headers: {
            'Content-Type': 'application/json',
            'Cache-Control': 'no-cache',
        },
    });
};