This application serves as a user-friendly URL aliasing server. Users can provide long URLs, and the server generates shortened aliases that redirect to the original URLs. The aliases act as convenient shortcuts for accessing the original links.
To get started, follow these steps to build the url-aliaser server:
- Clone the repository and navigate to the cloned directory.
- Build the application using the
gocommand:
go build ./...Upon successful compilation, you'll find a new executable named url-aliaser
in the current directory.
You can run unit tests to ensure the application functions correctly. Use the following command to execute the tests:
go test ./...The URLAliaser server runs by default on http://localhost:8080.
To create a shortened alias, make a POST request to the `/alias`` endpoint with a JSON payload. The payload must adhere to the following structure:
{
"url" : "https://example.com",
"length" : 10
}url: The original link you want to shorten (required).length: The desired maximum length of the shortened alias (required).
The server will store the provided URL, generate a new alias, and respond with the following JSON payload:
{
"url" : "http://localhost:8080/xxxx"
}url: The shortened alias, wherexxxxis a randomly generated string matching the requested length.
In the following command, replace https://example.com with the url you wish to alias.
$ curl -X POST -H "Content-Type: application/json" -d '{"url": "https://example.com", "length":10}' http://localhost:8080/alias
{"url":"http://localhost:8080/100680ad54"}After this command, you can use http://localhost:8080/100680ad54 as a
redirection to https://example.com.