GithubHelp home page GithubHelp logo

url_shortener's Introduction

Simple URL Shortener in Go

Description

The project supports:

  • Creating shortened urls for valid input url strings.
  • Fetching content based hosted at the original url using the shortened url string.

Running the application

  • docker-compose up &
  • go run main.go
  • By default applications will be available at localhost:8185

API Usage

  • Create shortened URL :

    • resource path: /url-shortener

    • method: POST

    • request payload

        {
          "originalUrl": "<original url to be shortened>",
          "requesterId": "<an identifier for requester>",
          "ExpiryDate": "<when the shortened url should exoiry>"
        } 
    • response codes: [201,400]

    • response payload:

       {
         "id": "unique id of the mapping between original url and shortened url",
         "originalUrl": "<the original url>",
         "expiryDate": "<expiry date for the mapping>",
         "shortenedUrl": "<the actual shortened url>",
         "createdDate": "<insert date of the mapping>",
         "requesterId": "<an identifier for requester>",
         "content": "<actual site content histed at originalUrl>"
      }
    • example call:

      curl --location --request POST 'http://localhost:8185/url-shortener' \
         --header 'Content-Type: application/json' \
         --data-raw '{
             "originalUrl" :"https://jsonplaceholder.typicode.com/",
             "requesterId": "sunny",
             "ExpiryDate": "2023-04-12T02:05:55Z"
         }'
      
    • example response:

      {
          "id": "4",
          "originalUrl": "https://jsonplaceholder.typicode.com/",
          "expiryDate": "2023-04-12T02:05:55Z",
          "shortenedUrl": "TmeFhogLWy",
          "createdDate": "2022-04-13T12:48:11Z",
          "requesterId": "sunny",
          "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta lesheet\" href=\"/style.css\....and so on"       }
  • Get shortened url :

    • resource path: /url-shortener/{shortUrlString}
    • method: GET
    • response codes: [200,404]
    • response payload:
     {
       "id": "unique id of the mapping between original url and shortened url",
       "originalUrl": "<the original url>",
       "expiryDate": "<expiry date for the mapping>",
       "shortenedUrl": "<the actual shortened url>",
       "createdDate": "<insert date of the mapping>",
       "requesterId": "<an identifier for requester>",
       "content": "<actual site content histed at originalUrl>"
    }
    • example call:
    curl --location --request GET 'http://localhost:8185/url-shortener/TmZcbm7O78'
    
    • example response:
      {
       "id": "1",
       "originalUrl": "https://jsonplaceholder.typicode.com/",
       "expiryDate": "2023-04-12T02:05:55Z",
       "shortenedUrl": "TmZcbm7O78",
       "createdDate": "2022-04-13T10:06:11Z",
       "requesterId": "sunny",
       "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head....and so on"
       }

Testing

  • Curently only integrations tests ara available in the integration_tests folder
  • Once application is running change directory to /integration_tests and execute:
       newman run URL_shortener_tests.postman_collection.json
    

Possible future enhancements

- Add api, service and store tests.
- Consider fetching shortened url from dedicated unique service.
- Improve performance, current response time ~150-600ms. 

url_shortener's People

Contributors

sunnydas avatar

Watchers

 avatar  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.