No matches found in users.
Try switching to another result type using the tabs above.
You can access search results via JSON API by adding format=json
to your query:
https://codesearch.val.run/$2?q=fetch&page=1&format=json
For typeahead suggestions, use the /typeahead
endpoint:
https://codesearch.val.run/typeahead?q=fetch
Returns an array of strings in format "username" or "username/projectName"
Found 10800 results for "fetch"(383ms)
No matches found in users.
Try switching to another result type using the tabs above.
11}
1213async function fetchRandomWikipediaArticle(): Promise<{ title: string; extract: string; pageId: number } | null> {
14try {
15const response = await fetch('https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&meta=&generator=random&formatversion=2&exsentences=1&explaintext=1&grnnamespace=0');
16
17if (!response.ok) {
32return null;
33} catch (error) {
34console.error('Error fetching Wikipedia article:', error);
35return null;
36}
3839export default async function(req: Request): Promise<Response> {
40const article = await fetchRandomWikipediaArticle();
41
42if (!article) {
100<div class="error-card">
101<h1>Oops! Something went wrong</h1>
102<p>Unable to fetch a Wikipedia article. Please try again.</p>
103<a href="/" class="retry-link">Try Again</a>
104</div>
5## Features
67- **Server-Side Rendering**: All content is fetched and rendered on the server - no JavaScript required
8- **Random Article Fetching**: Uses the Wikipedia API to fetch random articles on each page load
9- **Beautiful Design**: Dark gray background with light gray card featuring sharp corners and yellow drop shadow
10- **Smooth Animations**: CSS-only animations for the card entrance effect
16## How it Works
17181. When a user visits the page, the server fetches a random Wikipedia article using the Wikipedia API
192. The server renders the complete HTML with the article title and first sentence extract embedded
203. The page displays immediately with a world icon as an SVG that links to the full article
36## Technical Implementation
3738- **Server-Side Rendering**: Built as a TypeScript HTTP val that fetches Wikipedia data server-side
39- **No JavaScript**: Completely static HTML with CSS-only animations
40- **Wikipedia API Integration**: Fetches random articles using the Wikipedia API on the server
41- **Error Handling**: Proper error states with retry functionality
42- **Clean Architecture**: Separation of data fetching and HTML generation
43- **Performance**: Fast loading since no client-side API calls are needed
44