Nest framework TypeScript starter repository implementing a shortening url service.
- git clone the repo
- Install mkcert, docker and docker-compose in your machine
cd
into the root directory and run the installer script./install.sh
(Support Unix based OS only)- Now you can reach the api by access nginx gateway through
https://shortening.local.com/
(PORT 80) - Configurations can be found in
.env.local
(root directory)
- Full development environment out of the box using
docker
anddocker-compose
- Mongodb as persistence layer
- Redis as cache layer
- Full code coverage unit testing for the main parts
- Rate limiter using
@nestjs/throttler
- Local git hooks for
linting
andtesting
usingyorkie
andlint-staged
- Git actions workflow for PR reviews (
linting
andtesting
) - Some
SOLID
principles - Some patterns like
repository
andEvent Emitter
- Logging all requests and responses
- i18n translation support
# unit tests
$ npm run test
# test coverage
$ npm run test:cov
- Import url-shortening-service.postman_collection into postman (found in the root dir)
- Navigate to
https://shortening.local.com/docs
Endpoint | Usage | Gateway Example |
---|---|---|
GET / |
Health check | https://shortening.local.com |
POST /api/v1/urls/encode |
given {"urlName: "www.google.com"} then it will generate a short id for it to be used later and redirected to the long urlName and save it in the db |
https://shortening.local.com/encode |
GET /api/v1/urls/decode |
given the url short id it will redirected to the long url name and will cache it in addtion to save vist country, visit count and inc total clicks |
https://shortening.local.com/559WLYubxkoB7PmkvJeHUi |
GET /api/v1/urls/statistics |
given a short id then it will return some url statistics like totalClicks and visits |
https://shortening.local.com/statistics/559WLYubxkoB7PmkvJeHUi |
- Author - Abdelrahman Abdelhamed