summaryrefslogtreecommitdiff
path: root/ping/frontend/src/routes/stocksapi/search/+server.ts
blob: e58fc6be7c320557aa36a41062fbd8f0a49974a9 (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/search?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.search(query, { region: 'US' })
    return new Response(JSON.stringify(data), {
        headers: {
            'Content-Type': 'application/json',
            'Cache-Control': 'no-cache',
        },
    });
};