👄 My simple worker for short links

Overview

👄 My simple worker for short links

I wanted a quick-and-easy way to create links on my domain, so I turned to Cloudflare Workers.
All routes available, apart from the base redirect, return a JSON response paired with the Content-Type: application/json header.
Every aforementioned JSON response follows this rough schema:

  • for successful POST requests:
{
  "success": true,
  "payload": {}
}
  • for successful DELETE and PUT requests:
{
  "success": true,
  "message": "Some message."
}
  • for any unsuccessful request:
{
  "success": false,
  "message": "Error message."
}

Aside from that, the API also requires authentication through the X-Auth-Key header.

🛣️ The routes

Requests to URLs other than / are handled by the worker and fall under the following spec.

GET /:slug

Runs a check against a bound KV namespace called LINKS, and if a slug like the one requested exists, redirects to the associated URL.
If the slug can't be found, a JSON response is returned.

POST /:slug?url={url}

Creates a case-sensitive entry in the KV namespace called slug with the value url.
Requests to the above endpoint are then redirected to corresponding URLs.
Upon successful creation (not a duplicate, etc.), a JSON response is returned:

{
  "success": true,
  "payload": {
    "slug": "The passed slug",
    "url": "The passed url"
  }
}

POST /new?url={}

Similar to the above, except, this route randomizes the slug using nanoid.
Since the slug is random, it's very important to save it by reading the response:

{
  "success": true,
  "payload": {
    "slug": "The nanoid-generated slug",
    "url": "The passed url"
  }
}

DELETE /:slug

Deletes a link associated with the slug.

PUT /:slug?url={url}

Update an existing slug with a new url. Doesn't return the new link like POST requests.

You might also like...

Short sample and instructions for configuring a Flutter Web application to deploy-on-push to Firebase Hosting

Short sample and instructions for configuring a Flutter Web application to deploy-on-push to Firebase Hosting

Nov 17, 2022

Execute obsidian commands with short key sequences. For example, 'tp' for 'Toggle Preview' and 'tb' for 'Toggle Sidebar'. Easier to remember.

Execute obsidian commands with short key sequences. For example, 'tp' for 'Toggle Preview' and 'tb' for 'Toggle Sidebar'. Easier to remember.

Key Sequence Shortcut Key Sequence Shortcut is an obsidian plugin, allow binding key sequences to an obsidian command. For example If we assume "t" st

Dec 26, 2022

Generate short video game music, automatically, endlessly.

Generate short video game music, automatically, endlessly.

short-VGM-generator (DEMO) Generate short video game music, automatically, endlessly. It is powered by machine learning with magenta.js HOW TO PLAY Pr

Oct 28, 2022

Superkeys allow users to add short keys for websites and make search query in those sites.

Superkeys allow users to add short keys for websites and make search query in those sites.

Superkeys is a browser extension which allow users to add short keys for websites and make search query in those sites. Made with ❤️ @nilooy 🧑‍💻 Dem

Aug 17, 2022

A dad joke is a short joke, typically a pun, presented as a one-liner or a question and answer, but not a narrative

A dad joke is a short joke, typically a pun, presented as a one-liner or a question and answer, but not a narrative. Many dad jokes may be considered anti-jokes, deriving humor from an intentionally not funny punchline. daddy-jokes is an npm package that returns a dad joke when implemented.

Oct 23, 2022

Share short notes with just a link. No database. No storage!

Patra | Share your notes! You can share short notes with just a link. No database. No storage! write short articles in markdown and share the link! wr

Nov 12, 2022

life is short, you need lis:)

HduLis life is short, you need lis:) Usage Installation npm i hdu-lis Cas login const {casLogin} = require("hdu-lis") const url ="https://cas.hdu.e

Nov 3, 2022

Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Feb 16, 2021

🪨 A simple obsidian plugin that links all modified files meeting certain criteria to a daily note

🪨 A simple obsidian plugin that links all modified files meeting certain criteria to a daily note

Obsidian List Modified This plugin lists all modified files meeting certain criteria to a daily note. Why? As of now, dataview queries cannot be "froz

Dec 7, 2022
Owner
Paul Przybyszewski
Hi! I'm Paul, also known as wulf. I am a student, software developer, and an avid dog lover.
Paul Przybyszewski
Sharing short code samples, logs or links is now easier than ever!

Pastebin Sharing short code samples, logs or links is now easier than ever. Explore the docs » • Report Bug • Request Feature • About The Project With

Prasoon Soni 4 Nov 26, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A simple and fast redirection tool (short link) written in Rust.

?? RabiJump 简体中文 | API Doc RabiJump is an open source redirection service aimed for efficiency and simplicity. ?? Features: Built-in filesystem databa

Rui Li 53 Oct 19, 2022
Short JavaScript code snippets for all your development needs

30 seconds of code Short JavaScript code snippets for all your development needs Visit our website to view our snippet collection. Use the Search page

30 seconds 106.1k Dec 30, 2022
Short CSS code snippets for all your development needs

30 seconds of CSS Short CSS code snippets for all your development needs Visit our website to view our snippet collection. Use the Search page to find

30 seconds 15.9k Jan 3, 2023
A short project to automatically upload multiple pictures to pinata.cloud

Papel Mache Papel Mache is an app that uploads pictures to IPFS through pinata.cloud Requirements pinata/sdk: 1.1.14 node: 14.17.6 Node Node installat

Cardano Valley 7 Aug 18, 2022
📝 You Can Create Your Own Short Notes With The Help of Sticky-Notes Website.

Hi ?? , I'm Sneh Agrawal A passionate Web developer from India ?? I’m currently working on Chatting Website Chit-Chat ?? How to reach me on My Gmail A

Sneh (Smilyboyy) 1 Feb 23, 2022
Short JavaScript code snippets for all your development needs

30 seconds of code Short JavaScript code snippets for all your development needs Visit our website to view our snippet collection. Use the Search page

30 seconds of code 106.1k Dec 28, 2022