URL Shortener with mysql support.
Just practicing the implementation of various languages.
- go
- java
- nodejs
-
up server
./build.java.sh # build java first # up server docker-compose up --build -d
Only the ports are different.
- go: 3001
- java: 3002
- nodejs: 3003
curl -X GET http://localhost:3001
# response: server alive!
POST /shorten
Attribute | Type | Required | Description |
---|---|---|---|
url |
url | yes | 要縮短的原網址 |
example:
curl -X POST \
-H "Content-Type:application/json" \
-d "{\"url\": \"http://www.google.com\"}" \
http://localhost:3001/shorten
200 OK
{
"id": 1,
"url": "http://www.google.com",
"shortId": "k3mau1pvbILo",
"createdAt": "2019-10-23T10:15:28.000+0000",
"updatedAt": "2019-12-31T10:15:28.000+0000",
"deletedAt": null
}
or
400 Bad Request
{
"error": "Invalid url"
}
GET /{shortId}
Attribute | Type | Required | Description |
---|---|---|---|
{shortId} |
String | yes | 縮網址ID |
example:
curl -X GET \
http://localhost:3001/k3mau1pvbILo
303 See Other
redirect to: http://www.google.com
or
404 Not Found
{
"error": "Not Found"
}