DEV Community

Cover image for A Simple server with Deno
Ganesh Raja
Ganesh Raja

Posted on • Updated on

A Simple server with Deno

I wanted to experiment with Deno and build a quick site. Here it is.

A Server that makes an API call to SpaceX and gets the image list. Whenever user makes a request it returns a random image. Started this to learn more about Deno

From my understanding it's still in the very early stages. But could be really healful for scripting with the permissions feature.We will see

You can find my Repo Link here

import { serve } from "";

const SPACE_X_URL = "";

const res = await fetch(SPACE_X_URL);
const response_json = await res.json();

const images_list = response_json["links"]["flickr_images"];

const server = serve({ port: 8000 });

for await (const req of server) {
  let img_url = images_list || images_list[Math.floor(Math.random() * images_list.length)];
  let response = `<h1>Hey, Here is one random Space X Image </h1> <img style='height:500;width:500' src="${img_url}"/>`;
  req.respond({ body: response });

Enter fullscreen mode Exit fullscreen mode

Top comments (0)