This project exposes two API's, first one POST takes a long URL and returns a shortened URL key and the second one takes key and returns full original url.This project uses inbuilt H2 Database to persist data.
All dependencies can be found in pom.xml , some of them are :
- spring-boot-starter-web (Spring boot framework)
- spring-boot-starter-data-jpa (for data persistence)
- spring-boot-starter-test (for tests)
- springfox-swagger-ui (for api docs)
To build this project, run
git clone https://github.com/munirajtomar/urlshortner.git
cd urlshortner
mvn clean install
mvn spring-boot:run
The application will be accessible on http://localhost:8080
You can access following API endpoints at http://localhost:8080/swagger-ui/
It takes a JSON object in the following format as payload
{
"originalUrl":"<The full URL which is to be shortened>"
}
curl -X POST \
http://localhost:8080/api/v1/url \
-H 'Content-Type: application/json' \
-d '{"originalUrl":"https://example.com"}'
Response:
{
"originalUrl": "abcd@example.com",
"urlKey": "973347"
}
This endpoint returns back the corresponding fullUrl.
curl -X GET http://localhost:8080/api/v1/url/abcdef
Response:
{
"id": 1,
"originalUrl": "abcd@example.com",
"urlKey": "973347"
}
email: muniraj.tomar91@gmail.com