Skip to content

MayankFawkes/short-url

Repository files navigation

Shorten URL

API

The API endpoints listed below are available.

Features

  • Faster with redis
  • Ratelimit on api with Gloabl IP ban
  • Light Weight & Easy to setup
  • Heroku Supported
  • One command installation

Installation

Docker

    
      docker-compose up -d
    
  
Gunicorn server will start on localhost:8000

Heroku

Deploy

POST /create/times

Create a shorter URL with Access Limits.

Request

Parameters:

  • url – [str] full url
  • times - [str, int] short code will be dead after TIMES visit

    
      curl -X POST \
      --data '{"url": "https://google.com", "times": "3"}' \
      -H "Content-Type: application/json" {{ domain }}/create/times
    
  

Response

    
      {"Auth":"7398e225-836e-4f60-9732-140cbf135e10","Code":"USTKUu","Created\
       At":"1616766726.4898272","Fullurl":"https://google.com","Times":"3"}
    
  

POST /create/time

Create a shorter URL with time.

Request

Parameters:

  • url – [str] full url
  • time - [str, int] short code will be dead after TIME seconds

    
      curl -X POST \
      --data '{"url": "https://google.com", "time": "3"}' \
      -H "Content-Type: application/json" {{ domain }}/create/time
    
  

Response

    
      {"Auth":"4f160d63-5ae2-4e28-a493-9c0e6b838768","Code":"vEXdWW","Created \
      At":"1616767277.039384","Fullurl":"https://google.com","Ttl In Seconds":"3"}
    
  

DELETE /delete

Delete create url.

Request

Parameters:

  • code – [str] shorte code
  • auth - [str] auth key of shorte code

    
      curl -X DELETE \
      --data '{"code": "C0uSZg", "auth": "e56e03bc-8d11-40f7-bcf6-f1254af053a6"}' \
      -H "Content-Type: application/json" {{ domain }}/delete
    
  

Response

    
      HTTP Status 204 (No Content)
    
  

POST /stats

Check your URL stats.

Request

Parameters:

  • code – [str] shorte code
  • auth - [str] auth key of shorte code

    
      curl -X POST \
      --data '{"code": "MK9qiH", "auth": "78afb120-6ab1-4f7f-a3ce-bce8e7a65693"}' \
      -H "Content-Type: application/json" {{ domain }}/stats
    
  

Response

    
      {"Access":"1","Auth":"78afb120-6ab1-4f7f-a3ce-bce8e7a65693","Code":"MK9qiH","Created \
      At":"1616767969.7141504","Fullurl":"https://google.com","Last Visit":"1616768016.03026","Times":"2"}
    
  

HTTP RESPONSE

    
      CODE                      MEANING
      ======================================================================================================
      200 (OK)                  The request completed successfully.
      204 (NO CONTENT)          The request completed successfully but returned no content.
      401 (UNAUTHORIZED)        The Authorization header was missing or invalid.
      403 (FORBIDDEN)           The Authorization token you passed did not have permission to the resource.
      404 (NOT FOUND)           The resource at the location specified doesn't exist.
      405 (METHOD NOT ALLOWED)  The HTTP method used is not valid for the location specified.
      429 (TOO MANY REQUESTS)   You are being rate limited, see Rate Limits.
      5xx (SERVER ERROR)        The server had an error processing your request (these are rare).
    
  

SERVER RESPONSE

    
      CODE    MEANING
      ==============================
      5000    SUCCESS
      5001    INVALID_DATA
      5002    RATE_LIMIT
      5003    NOT_FOUND
      5004    INVALID_URL
      5007    BLOCKED_IP
      5008    INVALID_SHORT_CODE
      5009    AUTH_FAILED