An open source ready for usage url shortener.
I have a public instance running that you can consume/use. You can access the Swagger docs with
https://s.mgbarbosa.dev/api/v1/docs
Feel free to use the API (as long there's no abuse) for shortening/testing the API.
- Creating new Shortened URL
- Fetching shorted URL
- Redirect endpoint
- Create User
- Create private url (that belongs to a specfic user)
- User's shortened URL management
- Auto-expiring URLs
- URL usage/metrics
The endpoints below are basic usage, there's also more features, but they are on beta, that being said, it will not be included for now.
curl -X POST 'https://s.mgbarbosa.dev/api/v1/shortener' \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.reuters.com/article/urnidgns002570f3005978d8002576f60035a6bb-idUS98192761820100330"}'
Response:
{
"id": "2b99abe2-1f24-4964-91e5-f7517f4dc16b",
"createdAt": "2023-02-20T00:04:27.977013737",
"originalUrl": "SOME_LONG_URL",
"shortenedUrl": "https://www.reuters.com/article/urnidgns002570f3005978d8002576f60035a6bb-idUS98192761820100330"
}
curl -X GET 'https://s.mgbarbosa.dev/api/v1/shortener/mjprJAuqhm'
Response:
{
"id": "2b99abe2-1f24-4964-91e5-f7517f4dc16b",
"createdAt": "2023-02-20T00:04:27.977013737",
"originalUrl": "SOME_LONG_URL",
"shortenedUrl": "https://www.reuters.com/article/urnidgns002570f3005978d8002576f60035a6bb-idUS98192761820100330"
}
This endpoint is exclusively for being redirect to the original url. Paste the URL below to your browser and you will be redirected.
https://s.mgbarbosa.dev/api/v1/redirect/mjprJAuqhm
There's already a configured docker-compose.yaml
file in the project root, so you can
easily start the project locally following the instructions:
- Open
docker-compose.yml
- Change the required environment variables
- If you build the image locally, change the image property
- Start the apps with
docker-compose up -d
You should be able to reach the app accessing http://localhost:8080/api/v1/ping
on your browser
- Make sure that you have docker running
- Pull the image with:
docker pull ghcr.io/m4urici0gm/url-shortener:latest
Start the container with
docker run --name some-url-shortener \
--restart always \
-e 'MONGODB_URL=<your-mongodb-connection-string>' \
-e 'JWT_ISSUER=http://localhost:8080' \
-e 'JWT_AUDIENCE=http://localhost:8080' \
-e 'JWT_EXPIRATION_SECONDS=7200' \
-e 'JWT_REFRESH_TOKEN_EXPIRATION_SECONDS=7200' \
-p 8080:8080 \
-d ghcr.io/m4urici0gm/url-shortener:latest
Check if the app is running with curl 'http://localhost:8080/api/ping' | json_pp
.
If everything went fine, you should be able to see the response like this:
{
"message" : "Im alive and well!"
}
Before you begin, ensure you have met the following requirements:
- Java JDK 17 or later
- A running mongodb instance.
- Fork the repository
- Make sure you have a running mongodb instance
- Creates (if it doesnt exist) a .env file on the project root (You can use the template below)
- Build the project with
./gradlew clean build
- Run the project with
./gradlew bootRun
- The app should be running at
http://localhost:8080
MONGODB_URL=mongodb://root:blueScreen#666@localhost:27017/url-shortener
JWT_ISSUER=http://localhost:8080/
JWT_AUDIENCE=url-shortener
JWT_SECRET=SOME_RANDOM_STRING
JWT_EXPIRATION_SECONDS=7200
JWT_REFRESH_TOKEN_EXPIRATION_SECONDS=7200
To contribute to this project, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes.
- Make sure that all unit tests passes with
./gradlew clean build jacocoTestReport
- Push to the original branch:
git push origin <project_name>/<location>
- Create the pull request.
Alternatively see the GitHub documentation on creating a pull request.
Thanks to the following people who have contributed to this project:
If you want to contact me you can reach me at [email protected]
This project uses the following license: Mozilla Public License Version 2.0.
Done with ❤️