short-url-service
目的:简单造轮子 + 复习旧的知识
项目介绍
简单短链服务器,算法参考
软件架构
依赖
servlet3.0+
HikariCP
Gson
lettuce redis
SPI
使用说明
clone git code
gradle tomcatRun
可以修改SPI实现,目前实现了简单内存实现和redis实现两种方式
提供了短链生成API,使用token + json + post方式
测试
请求生成短链样例
短链生成请求:
curl -v -i -X POST -H "Content-type:application/json" -H "token:123" -d '{"url":"https://www.baidu.com"}' http://localhost:8080/sus/create
短链生成响应:
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> POST /sus/create HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> Content-type:application/json
> token:123
> Content-Length: 31
>
* upload completely sent off: 31 out of 31 bytes
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Date: Sat, 15 Dec 2018 09:05:28 GMT
Date: Sat, 15 Dec 2018 09:05:28 GMT
<
{"code":0,"longUrl":"https://www.baidu.com","shortUrl":"Afi6Nb"}
* Connection #0 to host localhost left intact
使用短链访问样例
短链访问请求:
curl -v -i http://localhost:8080/sus/vQj2eq
短链访问响应:
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /sus/vQj2eq HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Server: Apache-Coyote/1.1
Server: Apache-Coyote/1.1
< Location: https://www.baidu.com
Location: https://www.baidu.com
< Content-Length: 0
Content-Length: 0
< Date: Sat, 15 Dec 2018 09:15:13 GMT
Date: Sat, 15 Dec 2018 09:15:13 GMT
<
* Connection #0 to host localhost left intact
后期功能扩展
目前是纯servlet项目,可以切换为springboot类型项目
token管理
后台管理功能