This project is yet another URL-shortener written as a test assignment.
The name of the project playfully reflects its purpose (to make any URL 'only' miles short) and also is a tribute to the Bujold's character Miles Vorkosigan, which is a very energetic persona, but, as the URLs after the application's done with it, is quite short and perhaps a little ugly.
This application is a rather simple application of Dropwizard Java Framework which produces just one jar. To install it from sources (and I currently don't provider binaries), you just have to clone the stable version from the repository (that being 0.3.0 currently) and build it with generic Maven:
git clone git@github.com:Sulion/miles-short.git
cd ./miles-short
git checkout tags/v0.3.0
mvn clean install
Maven build script will generate fat jar file named miles-short.jar
which is almost all you need to start an application:
mkdir -p ./runtime && java -jar target/miles-short.jar server config.yml
The default port is 8080
for business URLs and 8081
for administrative ones (you may find metrics and healthcheck
there). The directory ./runtime
is intended for persistens storage of application data, such as registered URLs and
accounts. You may symlink other directory instead with the same link name.
You may also customize ports, persistent DB location and returned in /register
REST method base address by editing
config.yml
. The example of such configuration is below:
server:
applicationConnectors:
- type: http
port: 9090
adminConnectors:
- type: http
port: 8091
logging:
level: INFO
loggers:
ru.sulion.web-applications: DEBUG
httpUrl: https://miles-short.herokuapp.com:8080
dbFileName: ./otherLocation/otherdbname.db
HTTP method | POST |
URI | /account |
Request type | application/json |
Request Body | JSON object with the following parameters: AccountId (String, mandatory, length is less than or equals 200 characters: no overflow in my house) Example: { "AccountId" : "myAccountId"} |
Reponse Type | application/json |
Response | We distinguish the successful from the unsuccessful registration.
Unsuccessful registration occurs only if the concerned account ID already exists. The parameters are as follows:
|
HTTP metod | POST |
URI | /register |
Request type | application/json |
Request Headers | Authorization header with Basic authentication token |
Request Body | JSON object with the following parameters:
|
Reponse Type | application/json |
Response | Response parameters in case of successful registration are as follows:
|
HTTP metod | GET |
URI | /statistic/{AccountId} It's kinda obvious, but {AccountId} is constrained the same as the original value which is supposed to be given here: no more than 200 characters. |
Request Headers | Set Authorization header and authenticate user |
Reponse Type | application/json |
Response | The server responds with a JSON object, key:value map, where the key
eis the registered URL, and the value is the number of this URL redirects. Example: { "http://myweb.com/someverylongurl/thensomedirectory/": 10, "http://myweb.com/someverylongurl2/thensomedirectory2/": 4, "http://myweb.com/someverylongurl3/thensomedirectory3/": 91, } |
This is fairly simple, just query the url which /register
method has given you.