Skip to content

ZakaryaMeddahi/URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Live

https://url-shortener-tau-sooty.vercel.app/

Instalation

Clone repository (local branch):

git clone -b local https://github.com/ZakaryaMeddahi/URL-Shortener.git

Navigate to server folder:

cd server

Install node dependencies:

npm install

Create .env file and add your Atlas mongoDB URI in it, here is an example:

MONGO_URI=mongodb+srv://<username>:<password>@<cluster>.mfmabgc.mongodb.net/<dbname>?retryWrites=true&w=maj

Then add port, client side url and API endpoint in .env as well:

PORT=3000
CLIENT_DOMAIN=http://localhost:5500/client/
SERVER_DOMAIN=http://localhost:3000/

Start the application with this command line:

npm run start

Now you can start the frontend live server on port 5500 then navigate to http://localhost:5500/client/login.html Congratulation 🥳

API Design

Authentication

Register

Endpoint(URL): /api/v1/auth/register
Request Method: POST
Request Body

  {
    "username": <USERNAME>,
    "email": <EMAIL>,
    "password": <PASSWORD>
  }

Success Response Body

  {
    "success": "true",
    "user": {
      "id": <ID>,
      "username": <USERNAME>
    }
  }

Failure Response Body (Bad Request)

  {
    "success": "false",
    "message": "Invalid username, email, password!"
  }

Login

Endpoint(URL): /api/v1/auth/login
Request Method: POST
Request Body

  {
    "email": <EMAIL>,
    "password": <PASSWORD>
  }

Success Response Body

  {
    "success": "true",
    "user": {
      "id": <ID>,
      "username": <USERNAME>
    }
  }

Failure Response Body (Not Found)

  {
    "success": "false",
    "message": "Incorrect password!"
  }

Failure Response Body (Bad Request)

  {
    "success": "false",
    "message": "Invalid email, password!"
  }

Shortcuts

Get All Shortcuts

Endpoint(URL): /api/v1/urls
Request Method: GET
Success Response Body

  {
    "success": "true",
    "shortcuts": [
      {
        "id": <ID1>,
        "pathname": <PATHNAME>,
        "url": <URL>
      },
      {
        "id": <ID2>,
        "pathname": <PATHNAME>,
        "url": <URL>
      }
    ]
  }

Create Shortcut

Endpoint(URL): /api/v1/urls
Request Method: POST
Request Body

  {
    "url": <URL>,
    "pathname": <PATHNAME>
  }

Success Response Body

  {
    "success": "true",
    "shortcut": {
      "id": <ID>,
      "pathname": <PATHNAME>,
      "url": <URL>
    }
  }

Failure Response Body

  {
    "success": "false",
    "message": "Cannot create a shortcut, Provide a URL please!"
  }

Get Shortcut

Endpoint(URL): /api/v1/urls/:id
Request Method: GET
Success Response Body

  {
    "success": "true",
    "shortcut": {
      "id": <ID>,
      "pathname": <PATHNAME>,
      "url": <URL>
    }
  }

Failure Response Body (Not Found)

  {
    "success": "false",
    "message": "There is no shortcut with ID <ID>!"
  }

Failure Response Body (Bad Request)

  {
    "success": "false",
    "message": "<ID> is not ID, Provide a valid ID please!"
  }

Update Shortcut

Endpoint(URL): /api/v1/urls/:id
Request Method: PUT
Request Body

  {
    "url": <URL>,
    "pathname": <PATHNAME>
  }

Success Response Body

  {
    "success": "true",
    "url": {
      "id": <ID>,
      "pathname": <PATHNAME>,
      "url": <URL>
    }
  }

Failure Response Body (Not Found)

  {
    "success": "false",
    "message": "There is no shortcut with ID <ID>!"
  }

Failure Response Body (Bad Request)

  {
    "success": "false",
    "message": "<ID> is not ID, Provide a valid ID please!"
  }

Redirecting To URL

Endpoint(URL): /:pathname
Request Method: GET
Success Response Body
REDIRECT TO <URL> Failure Response Body (Not Found)
REDIRECT TO not-found page

About

URL Shortener App Using HTML, CSS, Node JS and MongoDB for Storing URLs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published