The server is responsible for handling user authentication, URL shortening, analytics, and other backend functionalities.
- Golang: Programming language used for backend development.
- Gin: Web framework for Golang, used for building web applications.
- go-jwt: Library for JSON Web Tokens (JWT) implementation in Golang, used for user authentication and session management.
- MongoDB: NoSQL database used for storing user account information, URL mappings, and analytics data.
- imagekit: Go client library for the ImageKit.io API, used for saving generated QR code images.
- go-qr-code: Library for generating QR codes in Golang.
- mail-trap: Library for send emails, this application specifically uses mailtrap templates accessed via API.
- godotenv: Go library for loading environment variables from a .env file.
To get started with the project, clone the repository and run:
go mod download
or
go mod tidy
Create a new file in ./server
directory called .env
and copy & paste what is in .env.example
into it:
# SERVER configs
PORT=
GIN_MODE=debug # Options: debug, release, test
BASE_URL=
CLIENT_URL=
URL_REDIRECT_PREFIX=
MONGO_URI=
JWT_SECRET=
# MAILTRAP configs
MAILTRAP_SENDER_EMAIL=
MAILTRAP_AUTH=
# EMAIL TEMPLATE IDs
RESET_PASSWORD_TEMPLATE_UUID=
EMAIL_VERIFICATION_TEMPLATE_UUID=
# IMAGEKIT configs
IMAGEKIT_PUBLIC_KEY=
IMAGEKIT_PRIVATE_KEY=
IMAGEKIT_URL_ENDPOINT=
Make sure to replace the placeholders with your actual credentials.
Start the server by running:
go run main.go
Sure! Here are all the endpoints defined for both the user and URL routers:
-
POST /v1/api/users/
- Description: Register a new user.
- Handler:
HandleSignup
function in thecontrollers
package. - Body:
{ "email": "", // required "password": "", // required "fullName": "" // required }
-
POST /v1/api/users/login
- Description: Log in an existing user.
- Handler:
HandleLogin
function in thecontrollers
package. - Body:
{ "email": "", // required "password": "" // required }
-
POST /v1/api/users/verify
- Description: Verify user email address.
- Middleware: Requires authentication token.
- Handler:
HandleEmailVerification
function in thecontrollers
package. - Body:
{ "token": "" }
-
GET /v1/api/users/resend-verification-token
- Description: Resend email verification token.
- Middleware: Requires authentication token.
- Handler:
HandleEmailVerificationTokenResend
function in thecontrollers
package.
-
POST /v1/api/users/forgot-password
- Description: Initiate forgot password flow.
- Handler:
HandleForgotPassword
function in thecontrollers
package. - Body:
{ "email": "" // required }
-
PATCH /v1/api/users/reset-password
- Description: Reset user password.
- Middleware: Requires authentication token.
- Handler:
HandlePasswordReset
function in thecontrollers
package. - Query Params:
{ "token": "" // required }
- Body:
{ "password": "" // required }
-
GET /v1/api/users/me
- Description: Get user profile.
- Middleware: Requires authentication token.
- Handler:
GetUserProfile
function in thecontrollers
package.
-
PATCH /v1/api/users/edit
- Description: Edit user full name.
- Middleware: Requires authentication token.
- Handler:
HandleUserFullNameEdit
function in thecontrollers
package. - Body:
{ "fullName": "" // required }
-
POST /v1/api/urls/
- Description: Create a new shortened URL.
- Middleware: Requires authentication token.
- Handler:
HandleCreateShortUrl
function in thecontrollers
package. - Body:
[]{ "url": "", // required "alias": "", "expireDate": "" }
-
GET /v1/api/urls/
- Description: Retrieve all URLs shortened by the user.
- Middleware: Requires authentication token.
- Handler:
GetUrlsByUserID
function in thecontrollers
package. - Query Params:
{ "page": "", "limit": "" }
-
DELETE /v1/api/urls/:id/delete
- Description: Delete a shortened URL by its ID.
- Middleware: Requires authentication token.
- Handler:
HandleUrlDelete
function in thecontrollers
package.
-
GET /redirect/:slug
- Description: Redirect to the original URL associated with the given slug.
- Handler:
RedirectToLongUrl
function in thecontrollers
package.
- Golang: Official Website
- Gin: GitHub Repository
- go-jwt: GitHub Repository
- Imagekit: Official Website
- go-qr-code: GitHub Repository
- MongoDB Go Driver: Official Website
- godotenv: GitHub Repository
- Mailtrap: GitHub Repository