Skip to content

Latest commit

 

History

History
145 lines (109 loc) · 2.78 KB

README.md

File metadata and controls

145 lines (109 loc) · 2.78 KB

Linkly RS

Bitly, but on rust

Linkly RS is a url shortner service built on Rust using the Rocket web server framework, Redis and PostgreSQL database. It's easy to host, just have the rust tool chain installed on your system and an env file with the configuration below.

ROCKET_PORT=1234
REDIS_URL=redis://<url>
DATABASE_URL=postgres://<username>:<password>@<url>/linkly_rs

# NOTE
# - There must always be DATABASE_URL because that's what sqlx uses to query macros online
# - You MIGHT run into docker issues if your env file has space and/or quotes


Now, in your directory, run

$ cargo run

API

This service offers 4 end points

  • GET /
    This is a health check end point.


    Response

    // OK - 200
    {
      "connected": true
    }

  • POST /url
    Add new url


    Body

    // x-www-form-urlencoded
    {
      "url": "onfranciis.dev"
    }

    Response

    // OK - 200
    {
      "result": {
        "id": 5,
        "long": "http://onfranciis.dev",
        "short": "a4f8",
        "date": "05 Jun-2024 06:58:00am +0100"
      },
      "err": null
    }
    // Conflict - 409
    {
      "result": null,
      "err": "Seems like this url has already been shortened! Is it 'a4f8' ?"
    }

  • GET /url/{id}
    Redirect if successful


    Response

    // Not Found - 404
    {
      "result": null,
      "err": "This url is invalid! Kindly confirm"
    }
  • GET /url
    Return all urls


    Response

    // OK - 200
    {
      "result": [
        {
          "id": 3,
          "long": "http://google.com",
          "short": "00a5",
          "date": "02 Jun-2024 13:40:56pm +0100"
        },
        {
          "id": 5,
          "long": "http://onfranciis.dev",
          "short": "a4f8",
          "date": "05 Jun-2024 06:58:00am +0100"
        },
        {
          "id": 6,
          "long": "http://test.com",
          "short": "e423",
          "date": "05 Jun-2024 07:06:43am +0100"
        }
      ],
      "err": null
    }

Rust Postgres Linux VS Code Insiders Redis

For support and enquiries, reach out via [email protected]