25 }
26
27 const response = await fetch(`/import-github?url=${encodeURIComponent(projectUrl)}`, {
28 method: "POST",
29 headers: {
105});
106
107export default app.fetch;
29 const posts = files.filter((file) => file.path.startsWith("posts/"));
30 const postContents = await Promise.all(
31 posts.map(async (file) => await (await fetch(file.links.module)).text()),
32 );
33
29 const posts = files.filter((file) => file.path.startsWith("posts/"));
30 const postContents = await Promise.all(
31 posts.map(async (file) => await (await fetch(file.links.module)).text()),
32 );
33
26 try {
27 const fileContent = await file.text();
28 const response = await fetch('/process-file', {
29 method: 'POST',
30 headers: {
39
40 try {
41 const response = await fetch("/submit", {
42 method: "POST",
43 headers: {
159 <h3>External Code</h3>
160
161 <h4>Fetch</h4>
162 <p>Fetch is a way for one server to request data from another server. A fetch requires
163 two const variables. The first is const response = await fetch(url). The second is
164 const data = await response.json();. If you want to do something besides just retrieve data,
165 you need to add the method. Change the first line from const response = await fetch(url) to
166 await fetch(url, {
167 method: 'any method except GET',
168 headers: { 'Content-Type': 'application/json' },
171
172 <p>
173 To make a fetch request with authorization, you would write const response = await fetch('API endpoint')
174 followed by const data = await response.json() and include headers: { 'Authorization': 'token' } in
175 your request.
195const app = new Hono();
196app.get("/", HTTP_Guide);
197export default app.fetch;
105});
106
107export default app.fetch;
63/**
64 * Wrap the incoming request, inject the Deno env vars into the Hono app,
65 * and then call the Hono api entrypoint (`app.fetch`)
66 */
67export default async function(req: Request): Promise<Response> {
74 //
75 // If you don't want those values, remove them from the env object
76 return app.fetch(req, env);
77}
1import { fetch } from "npm:node-fetch";
2
3export default async function(req: Request): Promise<Response> {
9
10 try {
11 const response = await fetch("https://official-joke-api.appspot.com/random_joke");
12 if (!response.ok) {
13 throw new Error("Failed to fetch joke");
14 }
15 const joke = await response.json();
16 return Response.json({ joke });
17 } catch (error) {
18 console.error("Error fetching joke:", error);
19 return Response.json({ error: "Failed to fetch joke" }, { status: 500 });
20 }
21}