DEV Community

Cover image for How to make an API call using Deno
Alexandru-Dan Pop
Alexandru-Dan Pop

Posted on • Edited on

6 5

How to make an API call using Deno

Without trying to start any more hype for Deno today, I'm just going to show an example of doing a HTTP call with this shiny new tool.

Show me the code

import { soxa } from 'https://deno.land/x/soxa/mod.ts'

const welcomeText = "Welcome to Deno.. a random joke is being prepared for you...";
console.log(`\n ${welcomeText} \n`);

async function fetchData() {
  try{
    const result = await soxa.get('https://api.icndb.com/jokes/random');
    console.log(`${result.data.value.joke} \n`);
  } catch (err) {
      console.error(err);
  }

}

fetchData();
Enter fullscreen mode Exit fullscreen mode

Sandbox

In the JS ecosystem we have been spoiled with tools where we can try our code straightaway, and you can do this with Deno today using a sandbox:

Repl.it

So just copy-paste the code above in the Repl.it sandbox, click run, and enjoy.

We live some troubled times, so hopefully a Chuck Norris joke will put a smile on your face.

Img of repl.it sandbox running Deno

More interesting reads:

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (4)

Collapse
 
caroso1222 profile image
Carlos Roso

Great post, succinct and straight to the point, thanks!

Collapse
 
alexandrudanpop profile image
Alexandru-Dan Pop

Thanks!

Collapse
 
jwp profile image
JWP

Did they name the http client "soxa" ?

Collapse
 
alexandrudanpop profile image
Alexandru-Dan Pop • Edited

Rings a bell? 🙂
It's a community package, so not really "the" way to do it.
github.com/fakoua/soxa

Anyone can add third party modules and they appear here if you add them to their DB (it's pretty straight forward):
deno.land/x

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay