Simple URL Shortener built on top NodeJS with Hapi and Sequelize (MySQL).
Note: this API is still in alpha stage. this project is just for hobbyist.
- Custom URL.
- Random Generate URL.
- More features coming soon...
- API: Make it more stable & secure.
- Rewrite to TypeScript: Reduce bugs and improve security.
- Object schema validation.
- Unit Test (use lab, mocha)
- API: User can custom number of digits of customURL.
- API: Follow RESTful API principle/standard
- Frontend: FE for client, admin
- Documentation: Easy to read and follow.
- Documentation: Guide for Deploying project.
- Misc: Add Licensing.
- Jul 16: First Launching!
-
Before start
- Make sure you have MySQL installed in your operating system.
- Optional:
- MySQL Workbench or DBeaver - MySQL Client.
- Insomnia or Postman - API Client.
-
Clone Repo
git clone https://github.com/Indra2108/sus.git cd sus npm install
-
Start MySQL service
sudo systemctl start mysqld
make sure if
mysqld
running properly withsystemctl status mysqld
.[indra@fedora ~]$ systemctl status mysqld ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2022-07-14 21:38:18 WIB; 15h ago Process: 11216 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Process: 11238 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Main PID: 11276 (mysqld) Status: "Server is operational"
-
Create Database
npx sequelize-cli db:create
-
Create Table
- Go to directory
src/dbconfig/models/index.js
- Uncomment the line 37
sequelize.sync({ force: true })
- run
node src/dbconfig/models/index.js
- Comment the line 37
// sequelize.sync({ force: true })
- run
npm test
- Go to directory
Base URL: http://localhost:3000
-
[POST]
/sendurl
- Description: Client send JSON. User can custom their originalURL in customURL. if you fill blank on customURL, the server will automatically random generate the URL.
- Request body type:
JSON
- Request body value:
originalURL
: type:string
, allowNull: falsecustomURL
: type:string
, allowNull: true
- Request body:
{ "originalURL": "<ORIGINAL-URL-STRING>", "customURL": "<USER-COSTUMIZED-URL-STRING>" }
- Endpoint example:
http://localhost:3000/sendurl
- Request body example:
{ "originalURL": "https://developer.mozilla.org/en-US/", "customURL": "mdn" }
{ "originalURL": "https://developer.mozilla.org/en-US/", "customURL": "" // server will automatically random generate the URL, if you fill this blank }
-
[GET]
/:params
- Description: User insert customURL to get redirected to the website.
- Request type:
params
- Example:
http://localhost:3000/mdn
http://localhost:3000/KH0cm // if you previously leave the customURL blank.