Skip to content

A URL shortener application built on Node.js and Express, utilizing PostgreSQL for data storage and JWT for user authentication.

Notifications You must be signed in to change notification settings

MikhailWahib/url-shortener-backend

Repository files navigation

URL Shortener App Documentation

Installation:

npm install

Usage:

npm run dev # starts dev server
npm run build # builds production
npm run start # starts production server

API Endpoints:

  1. User Registration:

    • Endpoint: /api/v1/users
    • Method: POST
    • Request:
      {
      	"username": "string",
      	"password": "string"
      }
    • Response:
      {
      	"message": "string",
      	"user": {
      		"id": 1,
      		"username": "string"
      	}
      }
  2. User Login:

    • Endpoint: /api/v1/users/login

    • Method: POST

    • Request:

      {
      	"username": "string",
      	"password": "string"
      }
    • Response:

      {
      	"message": "string"
      }
      
      // token sent to user in httpOnly cookie
  3. User Logout:

    • Endpoint: /api/v1/users/logout

    • Method: POST

    • Response:

      {
      	"message": "string"
      }
      
      // clears httpOnly cookie
  4. Get User's URLs:

    • Endpoint: /api/v1/users/urls
    • Method: GET
    • Authorization: handled by JWT middleware (no need for sending token)
    • Response:
      {
      	"urls": [
      		{
      			"id": "number",
      			"originalUrl": "string",
      			"shortUrl": "string"
      		}
      	]
      }
  5. URL Shortening:

    • Endpoint: /api/v1/shorten/{url}
    • Method: POST
    • Authorization: handled by JWT middleware (no need for sending token)
    • Response:
      {
      	"id": "number",
      	"originalUrl": "string",
      	"shortUrl": "string"
      }
  6. Redirect to Original URL:

    • Endpoint: /s/{shortcode}
    • Method: GET
    • Response:
      • Redirects to the original URL associated with the provided shortcode.

Stack:

  • Node.js
  • Express
  • TypeScript (TS)
  • PostgreSQL
  • JSON Web Token (JWT)
  • Bcrypt

About

A URL shortener application built on Node.js and Express, utilizing PostgreSQL for data storage and JWT for user authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published