DEV Community

scotia1973-bot
scotia1973-bot

Posted on

Build a URL Shortener with Free UUID + QR APIs

Build a URL shortener in 20 lines:

import express from "express";
const app = express();
app.use(express.json());
const store = new Map();

app.post("/shorten", async (req, res) => {
  const uuidResp = await fetch("https://api.gadgethumans.com/uuid?count=1");
  const { uuid } = await uuidResp.json();
  const code = uuid[0].split("-")[0];
  store.set(code, req.body.url);
  res.json({
    short: `https://short.url/${code}`,
    qr: `https://api.gadgethumans.com/qr?text=https://short.url/${code}`
  });
});

app.get("/:code", (req, res) => {
  return res.redirect(store.get(req.params.code) || "/");
});
app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

Both APIs free, no key. api.gadgethumans.com

Top comments (0)