github.com/Redstoneguy129/cli@v0.0.0-20230211220159-15dca4e91917/internal/functions/new/templates/index.ts (about)

     1  // Follow this setup guide to integrate the Deno language server with your editor:
     2  // https://deno.land/manual/getting_started/setup_your_environment
     3  // This enables autocomplete, go to definition, etc.
     4  
     5  import {serve} from "https://deno.land/std@0.168.0/http/server.ts"
     6  
     7  console.log("Hello from Functions!")
     8  
     9  serve(async (req) => {
    10    const { name } = await req.json()
    11    const data = {
    12      message: `Hello ${name}!`,
    13    }
    14  
    15    return new Response(
    16      JSON.stringify(data),
    17      { headers: { "Content-Type": "application/json" } },
    18    )
    19  })
    20  
    21  // To invoke:
    22  // curl -i --location --request POST 'http://localhost:54321/functions/v1/' \
    23  //   --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \
    24  //   --header 'Content-Type: application/json' \
    25  //   --data '{"name":"Functions"}'