> For the complete documentation index, see [llms.txt](https://docs.digit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digit.org/platform/build/core-services/url-shortening-service.md).

# URL Shortening Service

## Overview <a href="#overview" id="overview"></a>

The URL shortening service is used to shorten long URLs. There may be a requirement when we want to avoid sending very long URLs to the user via SMS, WhatsApp etc. This service compresses the URL.

## Pre-requisites <a href="#pre-requisites" id="pre-requisites"></a>

Before you proceed with the configuration, make sure the following pre-requisites are met -

1. Prior knowledge of Java/J2EE
2. Prior knowledge of SpringBoot
3. Prior knowledge of REST APIs and related concepts like path parameters, headers, JSON etc.

## Key Functionalities <a href="#key-functionalities" id="key-functionalities"></a>

1. Compress long URLs
2. Converted short URLs contain id, which is used by this service to identify and get longer URLs.

<table><thead><tr><th width="240">Environment Variable</th><th>Description</th></tr></thead><tbody><tr><td>host.name</td><td>Host name to append in short URL</td></tr><tr><td>db.persistance.enabled</td><td>The boolean flag stores the short URL in the database when the flag is set as TRUE.</td></tr></tbody></table>

## Deployment Details <a href="#deployment-details" id="deployment-details"></a>

* Deploy the latest version of the URL Shortening service

## API Details <a href="#api-details" id="api-details"></a>

#### a) `POST /egov-url-shortening/shortener` <a href="#a-post-egov-url-shortening-shortener" id="a-post-egov-url-shortening-shortener"></a>

Receive long URLs and converts them to shorter URLs. Shortened URLs contain URLs to the endpoint mentioned next. When a user clicks on shortened URL, the user is redirected to a long URL.

#### b) `GET /{id}` <a href="#b-get-id" id="b-get-id"></a>

This shortened URL contains the path to this endpoint. The service uses the id used in the last endpoint to get the long URL. In response, the user is redirected to the long URL.

## Reference Docs <a href="#reference-docs" id="reference-docs"></a>

## Play around with the API's : [DIGIT-Playground](https://digit-api.apidog.io/doc-507201)

### Doc Links <a href="#doc-links" id="doc-links"></a>

| Title                                                                                                                                                          |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Swagger API Contract](https://editor.swagger.io/?url=https://raw.githubusercontent.com/egovernments/core-services/master/docs/url-shortening_contract.yml#!/) |
| [URL Shortening Local Setup](https://github.com/eGovStack/core-services/blob/master/egov-url-shortening/LOCALSETUP.md)                                         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.digit.org/platform/build/core-services/url-shortening-service.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
