short-url
This is a simple URL shortener written in node.js and express.js with a MongoDB database.
Installation
- Clone the repository
- Install the dependencies
npm install
- Create a .env file and add the following:
MONGO_URI=<your mongodb uri>
JWT_KEY=<your jwt secret>
- Run the server
npm start
Usage
Register
Send a POST request to /api/user/signuo with the following body:
{
"username": "username",
"email": "email",
"password": "password"
}
Login
Send a POST request to /api/user/login with the following body:
{
"email": "email",
"password": "password"
}
Create a short URL
Authorization header is required. Authorization: Bearer <token>
Send a POST request to /api/short with the following body:
{
"url": "url",
"code": "code (not required)"
}
Get code information
Send a GET request to /api/url/:code .
Try the short URL
Send a GET request or enter on the browser the following URL: /r/:code.