A Tiny URL (API) server in Go
Have Go > 1.13 installed
go get github.com/chrisvdg/gotiny
cd %GOPATH/src/github.com/chrisvdg/gotiny
go build -mod vendor
# Build images
docker build -t gotiny .
# Run basic http server
docker run -p 80:80 gotiny
# Run with custom arguments
docker run --rm gotiny --help
A client library is available in the gotiny_client repository.
The following examples use CURL
instead.
Launch a gotiny server on the default port (":8080"),
without any authentication and
pretty print the json output.
./gotiny -j
# Create a new entry using CURL (in another terminal window)
curl -d "id=google&url=google.com" -X POST http://localhost:8080/api/tiny
{
"id": "google",
"url": "http://google.com",
"created": 1590330837
}
In a webbrowser surf to http://localhost:8080/api/tiny/google
where it should directed to the Google home page.
# Create a new entry with a generated ID
curl -d "url=chris.gent" -X POST http://localhost:8080/api/tiny
{
"id": "b2p76",
"url": "http://chris.gent",
"created": 1590331741
}
Now in a webbrowser go to http://localhost:8080/api/tiny/b2p76
where it should directed to my home page.
# List entries (you can also enter this URL into a browser)
curl http://localhost:8080/api/tiny
[
{
"id": "google",
"url": "http://google.com",
"created": 1590330837
},
{
"id": "b2p76",
"url": "http://chris.gent",
"created": 1590331741
}
]
# Get details of an entry (you can also enter this URL into a browser)
curl http://localhost:8080/api/tiny/google/expand
{
"id": "google",
"url": "http://google.com",
"created": 1590330837
}