Url Shortener API service provides functionality for managing shortened URLs. It allows users to generate, create, update, and delete shortened URLs. Users can also fetch the URLs associated with their accounts. This API is useful for building applications that require URL shortening capabilities, such as social media platforms, marketing campaigns, or any application that needs to generate shorter and more manageable URLs.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
For Users
- Description: Registers a new user.
- HTTP Method: POST
- Endpoint:
/user/signup
- Required Role: None
- Request Body: SignUpDto (username, password)
- Response: JWT token
- Description: Authenticates a user.
- HTTP Method: POST
- Endpoint:
/user/signin
- Required Role: None
- Request Body: SignInDto (username, password)
- Response: JWT token
- Description: Fetches all users.
- HTTP Method: GET
- Endpoint:
/user/list
- Required Role: ADMIN
- Request Body: None
- Response: Array of users (id, username, role)
- Description: Updates a user's information.
- HTTP Method: PUT
- Endpoint:
/user
- Required Role: ADMIN, USER
- Request Body: UpdateUserDto (username, oldPassword, newPassword)
- Response: Updated user information (id, username, role)
- Description: Deletes a user.
- HTTP Method: DELETE
- Endpoint:
/user/:userId
- Required Role: ADMIN
- Request Parameter: userId (integer)
- Response: None
For Url
- Description: Fetches the URLs associated with the user.
- HTTP Method: GET
- Endpoint:
/url/list
- Required Role: ADMIN, USER
- Request Body: None
- Query Parameters:
filters
UrlFiltersDto (search: string, expired: boolean
) - Response: Array of URLs
- Description: Creates a shortened URL.
- HTTP Method: POST
- Endpoint:
/url
- Required Role: ADMIN, USER
- Request Body:
body
CreateShortenedUrlDto (originalUrl: string, expirationDate?: Date, password?: string
) - Response: Created shortened URL
- Description: Updates a shortened URL.
- HTTP Method: PUT
- Endpoint:
/url/:urlId
- Required Role: ADMIN, USER
- Request Parameters:
urlId
(number) - Request Body:
body
UpdateShortenedUrlDto (originalUrl?: string, expirationDate?: Date, password?: string
) - Response: Updated shortened URL
- Description: Deletes a shortened URL.
- HTTP Method: DELETE
- Endpoint:
/url/:urlId
- Required Role: ADMIN, USER
- Request Parameters:
urlId
(number) - Response: None
I've managed to write only unit tests for this API, please feel free to expand the project, write integration & e2e tests and also add more features.
Thanks!