short-url
URL shortener is a small utility for generating and managing short URLs as aliases for long URLs
API
/health/
displays service health status
Return codes:
OK (200) is returned if service DB is working properly
PreconditionFailed (412) is returned otherwise
InternalServerError (500) is returned in case of general errors.
/shorts/
generates a short URL for the given long URL
body containing long URL in format {"long":"https://www.google.com"}
Input URLs for generating short URLs (generator API) are recieved in a body of a PUT request. Short URLs are created by adding the generated UUID to a base path.
Return codes:
OK (200) is returned when ran successfully, with the body containing generated short/long URL mapping.
NotAcceptable (406) is returned if long URL from request input can't be read to a string
UnprocessableEntity (422) is returned if decoded string is not a valid URL
InternalServerError (500) is returned in case of general errors.
/[:short_URL]
redirects to appropriate long URL
a path variable, short URL
Short URL is made of a generated UUID without hyphens
Return codes:
PermanentRedirect (308) on success. Request is redirected to corresponding long URL.
UnprocessableEntity (422) is returned if input short URL is not a valid UUID.
NotFound (404) is returned if short URL isn't found in the DB.
InternalServerError (500) is returned in case of general errors.
/hits/[:short_URL]
displays JSON about hits to the short URL, daily, weekly and total
a path variable, short URL
Return codes:
OK (200) on success, with the body being JSON with number of hits per day, week and in total.
UnprocessableEntity (422) is returned if input short URL is not a valid UUID.
NotFound (404) is returned if the UUID isn't found in the DB.
InternalServerError (500) is returned in case of general errors.
Build
From terminal, run 'source ./env', then 'make create_db', then 'make'
Run
'make run' or './short-url' from terminal
Unit tests
'make test' or 'go test ./...' from terminal for unit tests
Integration tests
If not ran already, run steps for building, then 'make run'
In another terminal, navigate to directory containing Makefile, then 'make integration'
File testing_plan contains instructions for manual testing (obviously, UUIDs will need to change)