Code Monkey home page Code Monkey logo

shorturl's Introduction

shorturl

Small app making short urls.

Example of the UI

Run

  1. Clone the repository

  2. go build

  3. Set the environment variables:

    • SHORTURL_POSTGRES_USER (f.e admin)
    • SHORTURL_POSTGRES_PASSWORD (f.e admin)
    • SHORTURL_SERVER_ADDRESS (f.e localhost:8000)

    For HTTPS support:

    • SHORTURL_HTTPS_ADDRESS (f.e localhost:8080)
    • SHORTURL_CERTFILE (public key, path to the .crt/.pem file)
    • SHORTURL_KEYFILE (private key, path to the .key file)
  4. ./shorturl

Requests

  1. Create short link

    Item Value required?
    URL shorturl.space/api/new yes
    Request type POST yes
    Request body(JSON) {urlOriginal: $url}, where $url is the URL to be shortened. yes
    Headers Content-Type: application/json yes

    Further request requirements:

    • $url must be a valid URL link (parsable by golang url.ParseRequestURI)
    • The URL Host in $url must not be shorturl.space
    • Request body must not exceed 8192 bytes
    • $url length must not exceed 2048 bytes

    Examples (TODO):

    Request Result
    POST /api/new, Content-Type: application/json, Request Body: {"urlOriginal": "https://example.com"} {"urlOriginal":"https://example.com","urlCode":"RML25P","expiresOn":"2024-06-19T20:10:14.006018-04:00"}
  2. Short link access

    Item Value required?
    URL shorturl.space/$code, where $code follows regex [1-9A-Z]{6} yes
    Request type GET yes

    Further request requirements:

    • $code must be valid (obtained through /api/new request and not expired)

    Response:

    • Static HTML page that redirects to the original URL linked to the $code.
    • Status code 200

    Errors:

    • 404 Not Found if the code isn't valid.
  3. Static files

    File Request
    ./index.html GET shorturl.space/
    ./index.css GET shorturl.space/index.css
    ./index.js GET shorturl.space/index.js

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.