# README
OZON INTERNSHIP REST API
Clone
- Clone from GitHub:
$ git clone https://github.com/Arcady1/OZON_Internship_API.git
- Prepare
.env
file:
PORT=8080
DB_HOST=127.0.0.1
DB_USER=<YOUR DB USER>
DB_PASSWORD=<YOUR PASSWORD>
DB_NAME=<YOUR DB NAME>
DB_SSLMODE=disable
DB_PORT=5432
Build and run
$ cd OZON_Internship_API/
$ go build -o app.bin
usage: ./app.bin l [local storage - default]
usage: ./app.bin p [postgresql storage]
Server is listening on localhost: 8080
Test
$ go test -v
Docker
- Clone the repository
- Start docker:
$ docker-compose up --build
Server is listening on localhost: 8080
- Stop docker:
$ docker-compose down
API
Get an original URL by short URL
Endpoint:
GET: http://127.0.0.1:8080/api/v1.0/url
Example request:
GET: http://127.0.0.1:8080/api/v1.0/url
?short=PBA4n_2n4s
Request parameters:
Parameter | Description | Required |
---|---|---|
short | The short URL. | True |
The example of the response for the short PBA4n_2n4s
{
"status": 200,
"message": "Getting the original URL",
"data": {
"originalURL": "https://google.com"
}
}
Response object:
Property | Description |
---|---|
status | The status of the response. |
message | Status description. |
data -> originalURL | The original URL. |
Get a short URL by original URL
Endpoint:
POST: http://127.0.0.1:8080/api/v1.0/url
Example request:
POST: http://127.0.0.1:8080/api/v1.0/url
?original=https://google.com
Request parameters:
Parameter | Description | Required |
---|---|---|
original | The original URL. | True |
The example of the response for the short https://google.com
{
"status": 201,
"message": "Original URL is saved",
"data": {
"shortURL": "PBA4n_2n4s"
}
}
Response object:
Property | Description |
---|---|
status | The status of the response. |
message | Status description. |
data -> shortURL | The short URL. |