> 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/local-governance/v2.7/platform/configure-digit/services-overview/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 are scenarios 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.

| Environmental Variable | Description                                                                   |
| ---------------------- | ----------------------------------------------------------------------------- |
| host.name              | Host name to append in short URL                                              |
| db.persistance.enabled | The boolean flag to store the short URL in database when flag is set as TRUE. |

## 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>

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

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

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

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

[![Creative Commons License](https://i.creativecommons.org/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)All content on this page by [eGov Foundation ](https://egov.org.in/)is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digit.org/local-governance/v2.7/platform/configure-digit/services-overview/core-services/url-shortening-service.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
