Git Product home page Git Product logo

shorturl's Introduction

ShortUrl

ASP.Net Core CĀ¤ implementation of an URL shortener much like "tinyurl.com", "bitl.y", "goo.gl", "ow.ly", etc...

Version 1

This is version 1. It only has a WebAPI and no webpage. It comes with near 100% unit test coverage.

Setup

Webserver

Solution is written in ASP.Net Core 2.0.

  1. Set up solution by publishing it to a folder and pointing a webserver at it. For example: Guide for setting up ASP.Net Core on IIS
  2. Change appsettings.json to configure a database. You should also change the UgradePassword.
  3. Visit http://yoururl.com/Admin/Upgrade/$$UPGRADEPWD$$ where $$UPGRADEPWD$$ is whatever you set UpgradePassword to. This will run EF Migrations and create your database.
  4. If the token database is empty, a default token is created. Check ShortUrlAccessToken table. Tokens are required for services to be able to create shorturls on system.

Note: Admin means it can initialize/upgrade database and request metadata for urls it did not create.

WebAPI

Create

Request

POST /Admin/Create
{
	"AccessToken": "$$TESTTOKEN$!!$CHANGEME$$",
	"Url": "http://mysite.com/$KEY$",
	"MetaData": "Put anything here, for example json",
	"Expires": "2018-01-01 15:30"
}

Note:

  • Expires is optional, and should be given in UTC.
  • $KEY$ in the URL will be replaced with the shorturl key. You can use this to pass reference for target solution to go back into ShortUrl system to pick up metadata. This way metadata can be passed in URL without going via user browser.

Response

{
	"success": true,
	"key": "abc123",
	"shortUrl": "http://myshorturlservice.com/abc123",
	"url": "http://www.stackoverflow.com/",
	"metaData": "Put anything here, for example json",
	"expiresUtc": "2018-01-01 15:30"
}

Get (metadata)

GET /Admin/Get/key?AccessToken=$$TESTTOKEN$!!$CHANGEME$$
{
	"accessToken": "$$TESTTOKEN$!!$CHANGEME$$",
	"url": "http://www.stackoverflow.com/$KEY$",
	"metaData": "Put anything here, for example json",
	"expiresUtc": "2018-01-01 15:30"
}

Initialize database (Migrations)

GET /Admin/Upgrade/$$UPGRADEPWD$$

Visit URL

Simply visit ShortUrl returned from Create operation to be forwarded to Url.

HTTPS

You may want to add automatic forwarding to HTTPS, maybe even with support for letsencrypt:

https://blog.tedd.no/2017/05/09/iis-redirect-http-to-https-but-allow-lets-encrypt/

shorturl's People

Contributors

tedd avatar mangowi avatar

Watchers

James Cloos 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.