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:
-
User Registration:
- Endpoint:
/api/v1/users
- Method:
POST
- Request:
{ "username": "string", "password": "string" }
- Response:
{ "message": "string", "user": { "id": 1, "username": "string" } }
- Endpoint:
-
User Login:
-
Endpoint:
/api/v1/users/login
-
Method:
POST
-
Request:
{ "username": "string", "password": "string" }
-
Response:
{ "message": "string" } // token sent to user in httpOnly cookie
-
-
User Logout:
-
Endpoint:
/api/v1/users/logout
-
Method:
POST
-
Response:
{ "message": "string" } // clears httpOnly cookie
-
-
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" } ] }
- Endpoint:
-
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" }
- Endpoint:
-
Redirect to Original URL:
- Endpoint:
/s/{shortcode}
- Method:
GET
- Response:
- Redirects to the original URL associated with the provided shortcode.
- Endpoint:
Stack:
- Node.js
- Express
- TypeScript (TS)
- PostgreSQL
- JSON Web Token (JWT)
- Bcrypt