When deplaying this way, two container will be created tinyUrl-app running the API server and tinyUrl-db running the postgresql instance.
To do so, use:
echo "DB_PASSWORD={password}" > .env
docker-compose up [-d]
The API server can however be ran locally if required, in that case tinyUrl-db container still needs to be deployed
To do so, use:
echo "DB_PASSWORD={password}" > .env
docker-compose -d db
DB_PASSWORD={password} make run
or
echo "DB_PASSWORD={password}" > .env
go mod download
go build -o app .
docker-compose -d db
DB_PASSWORD={password} ./app
To create a new shortened link, send a POST request to /links
The request MUST be done by authenticated users with x-auth-uuid header.
Example:
curl --header "Content-Type: application/json" --header "x-auth-uuid: {uuid}" --request POST --data '{"url": "google.com"}' 127.0.0.1:8080/links
To update a shortened link, send a PUT request to /links/{hash} where {hash} is the shortened link to modify.
The request MUST be done by authenticated users with x-auth-uuid header, the user MUST be the owner of the short link.
Example:
curl --header "Content-Type: application/json" --header "x-auth-uuid: {uuid}" --request PUT --data '{"url": "google.com"}' 127.0.0.1:8080/links/12XtEyOm
To delete a shortened link, send a DELETE reuqest to /links/{hash} where {hash} is the shortened link to delete.
The request MUST be done by authenticated users with x-auth-uuid header, the user MUST be the owner of the short link.
Example:
curl --header "Content-Type: application/json" --header "x-auth-uuid: {uuid}" --request DELETE --data '{"url": "google.com"}' 127.0.0.1:8080/links/12XtEyOm
To list your shortened link, send a GET request to /links
The request MUST be done by authenticated users with x-auth-uuid header.
Example:
curl --header "x-auth-uuid: {uuid}" 127.0.0.1:8080/links
To access the original link through a shortened link, send a GET request to /links/{hash} where hash is the shortened link to access.
This request requires no authentification.
When used in a web browser, the user will be automatically transfered to the original URL with a 302 HTTP answer
Example:
curl --header "x-auth-uuid: {uuid}" 127.0.0.1:8080/links/12XtEyOm
For all requests requiring to give an url (POST/PUT), the data format to send the url is the following:
{
"url": "myUrl.com"
}
For all requests the answer data format will be the following:
{
"data": [
{
"shortUrl": "12XtEyOm",
"baseUrl": "test.com"
},
]
"error": ""
}
In case of any other error than internal error, the data section will be empty and an error message will be availabel in the "error" field.
"data" section is populated depending on the query:
- POST: one element containing the generated short URL with URL it translates to
- PUT: one element containing the modified short URL with the new URL it translates to
- DELETE: empty data section
- GET
/links: one element for each owned short URL and the URL it translates to - GET
/links/{hash}: one element containing queried short URL with the url it translates to
It is to be noted that the link AAAAAAAA is unused since it represents id 0 while the database id starts at 1.