Public
Readme
This val shows how you can use the new dub.links.upsert
method to shorten a URL using the Dub API without creating duplicate links in your workspace for the given URL.
- SDK Docs: dub.links.upsert
- API Docs: api.dub.co/links/upsert
Code
HTTP
import { Dub } from "https://esm.sh/dub";
// import { Dub } from "dub"; <-- use this when using with a Node backend
const dub = new Dub({
token: Deno.env.get("DUB_API_KEY"), // optional – defaults to process.env.DUB_API_KEY
workspaceId: "ws_clw65kb1i000014o06p0qaczn", // Dub workspace ID – https://d.to/id
});
export default async function(req: Request): Promise<Response> {
const { shortLink } = await dub.links.upsert({
url: "https://www.val.town/v/steventey/dubLinksUpsert",
});
return Response.json({ shortLink });
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
evilsteventey-dublinksupsert.web.val.run
Updated: May 14, 2024