This project is a URL shortener developed for my course completion project. Its main objective is to have more control over the expiration of urls and validations of broken or nonexistent urls
access the api source code here: WEB
First clone this repository:
$ git clone https://github.com/BrendoSPinheiro/shrtn-it.git
second go to the web folder
$ cd ./web
third install the dependencies:
$ yarn
Or:
$ npm install
Was installed and configured the
eslint
to keep the code clean and patterned.
To start up the app run:
$ yarn start
Or:
$ npm start
access the api source code here: API
First clone this repository:
$ git clone https://github.com/BrendoSPinheiro/shrtn-it.git
second go to the server folder
$ cd ./server
third install the dependencies:
$ yarn
Or:
$ npm install
Was installed and configured the
eslint
to keep the code clean and patterned.
this application uses the PostgreSQL database.
Responsible for storing the data used by the application. For the fastest configuration it is recommended to use docker, you can create a postgresql container like this
$ docker run --name pg -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -p 5432:5432 -d postgres
You can find the application's
knexfile.js
file in the root folder. It already comes withtest
anddevelopment
connection configured, so you will update it only when deploying
Remember to run the PostgreSQL database migrations:
$ npx knex migrate:latest
Or:
$ yarn knex migrate:latest
See more information on Knex Migrations.
in this file, you will configure the jwt key.
key | description | default |
---|---|---|
JWTSECRET | A alphanumeric random string. Used to create signed tokens. | - |
To start up the app run:
$ yarn dev
Or:
$ npm run dev
A few routes expect a Bearer Token in an Authorization
header.
You can see these routes in the Routes section.
POST http://localhost:3001/urls Authorization: Bearer <token>
To achieve this token you just need authenticate through the /sessions
route and it will return the token
key with a valid Bearer Token.
route | HTTP Method | params | description | auth method |
---|---|---|---|---|
/urls |
GET | ❌ | Lists urls. | Bearer |
/urls/:id |
GET | :id of the URL. |
Get url details. | Bearer |
/:slug |
GET | :slug of the short url. |
Redirect short url. | ❌ |
/urls |
POST | Body with new short url data. | Create a new short url. | Bearer |
/urls/:id |
DELETE | :id of the URL. |
Delete short url. | Bearer |
/users |
POST | Body with new user data. | Create a new user. | ❌ |
/session |
POST | Body with user data. | User authentication. | ❌ |
Routes with
Bearer
as auth method expect anAuthorization
header. See Bearer Token section for more information.
POST /urls
Request body:
// to shorten an unscheduled URL
{
"title": "Google",
"full_url": "https://google.com"
}
// to shorten a URL with scheduling by date
{
"title": "Google",
"full_url": "https://google.com",
"scheduling_type": "date",
"start_expires_date": "2021-01-20",
"end_expires_date": "2021-01-22"
}
// to shorten a URL with scheduling by hour
{
"title": "Google",
"full_url": "https://google.com",
"scheduling_type": "hour",
"start_hour": 0,
"end_hour": 2
}
POST /users
{
"name": "Fulano",
"email": "[email protected]",
"password": "123456"
}
POST /session
{
"email": "[email protected]",
"password": "123456"
}
Brendo Souza Backend |
Matheus Oliveira Frontend |
Emmanoell Pasquet Author of the article |