This is the start repository for the project developed in this course.
The project is a Spring Boot application that offers a minimum set of functionalities shared by all subprojects.
- Short URL creation service:
POST /
creates a shortened URL from a URL in the request parameterurl
. - Redirection service:
GET /{id}
redirects the request to a URL associated with the parameterid
. - Database service: Persistence and retrieval of
ShortURL
andClick
objects.
The application can be run in Linux and macOS as follows:
$ ./gradlew bootRun
or in Windows
$ gradle.bat bootRun
Gradle will compile project and then run it Now you have a shortener service running at port 8080. You can test that it works as follows:
$ curl -v -d "url=http://www.unizar.es/" -X POST http://localhost:8080/link
> POST / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: */*
> Content-Length: 25
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 25 out of 25 bytes
< HTTP/1.1 201 Created
< Server: Apache-Coyote/1.1
< Location: http://localhost:8080/6bb9db44
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
{"hash":"6bb9db44","target":"http://www.unizar.es/","uri":"http://localhost:8080/6bb9db44",
"sponsor":null,"created":"2019-09-10","owner":"112b6444-0a05-4e48-a13f-27ddf23349e2","mode":307,
"safe":true,"ip":"0:0:0:0:0:0:0:1","country":null}%
Now, we can navigate to the shortened URL.
$ curl -v http://localhost:8080/6bb9db44
> GET /6bb9db44 HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
< Server: Apache-Coyote/1.1
< Location: http://www.unizar.es/
< Content-Length: 0
<
To generate the open api:
Run app -> On terminal "gradle bootrun"
On a webpage -> "http://localhost:8080/v3/api-docs.yaml" and open the .yaml generated. You can open "http://localhost:8080/v3/api-docs/" to obtain the .json open api