Skip to content

kelcecil/shorturl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shorturl

Example URL shortener written in Go

What is this?

This is an example web service for getting short urls. This example was written for use during my introductory code talk for the Morgantown Codes tech meetup on August 10th 2017.

Getting Started

  • Install Go from binaries available at the Go website.
  • Use go get github.com/kelcecil/shorturl or clone to your $GOPATH.
  • Do go run *.go.

Adding a URL

Just send a POST to the root with a JSON payload containing an attribute called "url":

{
  "url": "http://github.com"
}

You can use curl to easily add a URL from command line like so.

curl -X POST http://localhost:8080/ -H "Accept: application/json" -d '{"url":"http://github.com"}'

The JSON payload in response will containing a JSON attribute called key that you'll use for your short url.

{
  "key": "a"
}

Redirect to a URL

Just call the root like so using the key you received when submitting the URL.

curl -I -X GET http://localhost:8080/a

Your output will look something like:

HTTP/1.1 307 Temporary Redirect
Location: http://github.com
Date: Thu, 10 Aug 2017 21:21:03 GMT
Content-Length: 50
Content-Type: text/html; charset=utf-8

Try it in a web browser for maximum effect.

Potential Improvements

This example is intended to lead into a workshop session where people try running the application and make small improvements to the code to try their hand at Go programming. A few possibilities (in ascending order of difficulty) are:

Is this production ready?

Absolutely.

About

Example URL shortener written in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages