url-shortener-api

module
v0.0.0-...-ce4d510 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2024 License: MIT

README

Description:

Rest API for shortening urls

Self-hosting instructions:

  1. Clone the repository
  2. Install dependencies
    go mod download
    
  3. Run the server
    make run
    
  4. Run the tests
make tests

Save alias

  • POST /
      {
        "url": "https://www.google.com",
        "alias": "google"
      }
    

Delete alias

  • DELETE /:alias

Go to the shortcut link

  • GET /:alias

Features:

  • Redirect to the original url by the short url
  • If alias is not provided, generate a random alias
  • Creating, deleting urls are protected by auth
    • basic http auth
  • To store data use sqlite database
  • Api tries to decode json body, if it fails, returns failed to parse request message
  • Validates incoming requests
  • Logs all requests in text format in dev environment, and in json format in prod environment
  • Saving existing url, returns the same name message
  • Fails if alias is invalid
  • Fails if URL for given alias not found
  • Redirect only if successfully got URL

img.png Tests shows that api works correctly

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL