Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

tedd/ShortUrl

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED

There is a newer version at: https://github.com/tedd/Tedd.ShortUrl

. . . . . . . . . .

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/

About

ASP.Net Core implementation of an URL shortener.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.