Giter Site home page Giter Site logo

urlshortener's Introduction

UrlShortener

The solution consists of two projects.

  • urlshortener
  • apigateway

Actual functionality of shortening the url and storing it to the database is done by urlshortener.

Input

{
"longurl" : "abcdef"
}

Response

{
"shortUrl": "https://urlshortenerdec2020.azurewebsites.net/GPfgzDy",
"identifier": "9d3625e1-36bd-4773-a8dd-ebc420e5e2d8",
"createdOn": "2020-12-21T02:18:07.39+00:00"
}

If the url is already present, then it returns the same output along with the original created time. If url is absent in the database then it will create a new record in the database and return the above output.

apigateway is a facade over the service based on ocelot open source project. It provides the following functionality

  • rewrite /urlservice/v1/url to /urlservice/url. This means the request to /urlservice/url to apigateway is sent to /urlservice/v1/url to urlshortener service.
  • Ratelimiting to prevent any client from making too many requests within a short duration of time. It throws a message as given below "API calls quota exceeded! maximum admitted 1 per 5s."

The solution also contains a docker compose file, which refers to the following images. The docker compose file can be used locally to set up the solution

  • urlshortener
  • apigateway
  • mysqlserver

mysqlserver is the image for sql server + a few database objects that are required to function.

The solution (urlshortener + sqlserver database) is deployed on Microsoft Azure cloud and the api definition can be viewed using the url https://urlshortenerdec2020.azurewebsites.net/swagger/index.html. Swagger gives some information about how the api can be tested.

Docker components

Docker components in the solution consist of the docker files for following

  • urlshortener
  • apigateway

docker-compose file in the root folder refers to the following images in the public dockerhub repository

  • upendra409/apigateway
  • upendra409/urlshortener
  • upendra409/mysqlserver

Running docker-compose up command downloads the images from dockerhub and sets the solution on the local set up. The urlshortener api can be tested on "http://localhost:5200" end point.

The apigateway can be tested for post operations on "http://localhost:5199" end point. When it hits the urlshortener api it brings back the response

{
"shortUrl": "https://urlshortenerdec2020.azurewebsites.net/GPfgzDy",
"identifier": "9d3625e1-36bd-4773-a8dd-ebc420e5e2d8",
"createdOn": "2020-12-21T02:18:07.39+00:00"
}

Using the returned shortUrl in the browser will render the original url. Please note that running the sql container locally mai fail initially as the container itself takes some time to spin up & start running. Below is the log output when sql server starts.

2020-12-22 01:38:09.82 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database 'urlservice'. [CLIENT: 172.18.0.1] 2020-12-22 01:38:19.85 Logon Error: 18456, Severity: 14, State: 38. 2020-12-22 01:38:19.85 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database 'urlservice'. [CLIENT: 172.18.0.1] 2020-12-22 01:38:31.67 spid53 Starting up database 'urlservice'. 2020-12-22 01:38:31.85 spid53 Parallel redo is started for database 'urlservice' with worker pool size [1]. 2020-12-22 01:38:31.88 spid53 Parallel redo is shutdown for database 'urlservice' with worker pool size [1].

Changed database context to 'urlservice'.

urlshortener's People

Contributors

upendra409 avatar

Watchers

 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.