This Flask project implements a URL manager with six main functions:
Retrieves the URL associated with the given identifier.
Updates the URL associated with the given identifier with the new one provided in JSON format.
Deletes the identifier and its associated URL.
Retrieves all URLs along with their corresponding identifiers.
Generates a new identifier for the URL provided in JSON format using a custom hash algorithm.
Deletes all stored URLs and identifiers.
Create a new user with username and password and store it in a table
Update the user’s password if the user presents the correct old password
Check if username and password exist in the table and generate a JWT
You can install Flask simply using pip, run the following command in your terminal:
pip install flask
you can find more information on the website of Flask.
https://flask.palletsprojects.com/en/3.0.x/installation/
Clone this repository to your local machine.
Navigate to the project directory in your terminal.
Run the following command to start the Flask server:
flask --app main run
The server will start running locally on http://127.0.0.1:5000/.
You can call the services using curl, a command-line tool for transferring data with URLs. Here are examples of how to call each service:
curl -X GET -H "Content-Type: application/json" -H "Authorization: JWT" http://127.0.0.1:5000/<identifier>
curl -X PUT -H "Content-Type: application/json" -H "Authorization: JWT" -d '{"url": "https://example.com/new"}' http://127.0.0.1:5000/<identifier>
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: JWT" http://127.0.0.1:5000/<identifier>
curl -X GET -H "Content-Type: application/json" -H "Authorization: JWT" http://127.0.0.1:5000/
curl -X POST -H "Content-Type: application/json" -H "Authorization: JWT" -d '{"value": "https://example.com"}' http://127.0.0.1:5000/
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: JWT" http://127.0.0.1:5000/
curl -X POST -H "Content-Type: application/json" -d '{"username": "username", "password": "password"}' http://127.0.0.1:5000/users
curl -X PUT -H "Content-Type: application/json" -d '{"username": "username", "password": "old_password", "new_password":"new_password"}' http://127.0.0.1:5000/users
curl -X POST -H "Content-Type: application/json" -d '{"username": "username", "password": "password"}' http://127.0.0.1:5000/users/login