Back to articles
Val Town Has a Free API That Runs JavaScript Functions in the Cloud Instantly

Val Town Has a Free API That Runs JavaScript Functions in the Cloud Instantly

via Dev.to JavaScriptAlex Spinov

Val Town is a social website for writing and deploying JavaScript. Write a function, get an API endpoint — instantly, with zero deployment. Vals: Cloud Functions // A val = a function that runs in the cloud export function hello ( name : string ) { return `Hello, ${ name } !` ; } // Instantly available at: https://username-hello.web.val.run?name=World HTTP Val: Instant API export default async function ( req : Request ): Promise < Response > { const url = new URL ( req . url ); const category = url . searchParams . get ( " category " ); if ( req . method === " GET " ) { const products = await getProducts ( category ); return Response . json ( products ); } if ( req . method === " POST " ) { const body = await req . json (); const product = await createProduct ( body ); return Response . json ( product , { status : 201 }); } return new Response ( " Method not allowed " , { status : 405 }); } Deploy = save. That's it. Your function is live. Cron Val: Scheduled Jobs import { email } from

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles