URL Shortener is a server application that transforms long web links into shorter, more manageable ones.
URL Shortener allows users to create short URLs for long web links. This can be useful for shortening lengthy links in messages, text messages, or on social media, making them more convenient to share.
- Clone the repository:
git clone https://github.com/your_username/url-shortener.git
- Navigate to the project directory:
cd url-shortener
- Build the Go application:
go build .
- Run the application
go run main.go
Send a POST request to /api/urls with a JSON body containing the long URL:
POST /api/urls HTTP/1.1
Content-Type: application/json
{
"url": "https://example.com/very-long-url-that-we-want-to-shorten"
}
Or
curl -XPOST http:https://Localhost:8080/api/urls -d '{"url": "https://example.com/very-long-url-that-we-want-to-shorten"}'
Receive a response with the short URL:
{
"key": "0ve6V"
}
Open a browser and enter the URL in the format http:https://your-server/{key}, where {key} is the key obtained after creating the short link. For example:
http:https://your-server/0ve6V
Creates a short link.
Request Body Parameters
Parameter | Type | Description |
---|---|---|
Url | String | The long URL to be shortened. |
Redirects to the long URL associated with the short key.
Path Parameters
Parameter | Type | Description |
---|---|---|
key | String | The short key created when URL is added. |