GithubHelp home page GithubHelp logo

urlshortener's Introduction

๐Ÿ”— Node.js URL Shortener Function

Generate URL with short ID and redirect to the original URL when visited.

๐Ÿงฐ Usage

GET /:shortId

Redirects to shortId's original URL.

Parameters

Name Description Location Type Sample Value
shortId Short ID to lookup original URL. Path String discord

Response

Sample 302 Response:

Redirects to the original URL.

Location: https://discord.com/invite/GSeTUeA

Sample 404 Response:

When no URL is found for the short ID.

Invalid link.

POST /

Create a new short ID for a URL.

Parameters

Name Description Location Type Sample Value
Content-Type Content type Header application/json
long Long URL to shorten Body String https://mywebapp.com/pages/hugelongurl?with=query&params=123
shortCode Short ID to use, else will be automatically generated Body Optional String discord

Response

Sample 200 Response:

Returns the short URL and the original URL. The short URL is constructed from the SHORT_DOMAIN and the short code.

{
  "short": "https://short.app/s/discord"
}

Sample 400 Response:

When the URL parameter is missing.

{
  "ok": false,
  "error": "Missing url parameter."
}

โš™๏ธ Configuration

Setting Value
Runtime Node (18.0)
Entrypoint src/main.js
Build Commands npm install && npm run setup
Permissions any
Timeout (Seconds) 15

๐Ÿ”’ Environment Variables

APPWRITE_API_KEY

The API Key to talk to Appwrite backend APIs.

Question Answer
Required Yes
Sample Value d1efb...aec35
Documentation Appwrite: Getting Started for Server

APPWRITE_ENDPOINT

The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: https://cloud.appwrite.io/v1.

Question Answer
Required No
Sample Value https://cloud.appwrite.io/v1

APPWRITE_DATABASE_ID

The ID of the database to store the short URLs.

Question Answer
Required Yes
Sample Value urlShortener

APPWRITE_COLLECTION_ID

The ID of the collection to store the short URLs.

Question Answer
Required Yes
Sample Value urls

SHORT_BASE_URL

The domain to use for the short URLs. You can use your functions subdomain or a custom domain.

Question Answer
Required Yes
Sample Value https://short.app/s

urlshortener's People

Contributors

teamappwrite avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.