NodeJS service to short URLs
Requirements:
The chosen Database for this project is MongoDB .
THe application will use 2 environment variables to access the Database:
- MONGODB_HOST
- MONGODB_PORT
Set these and you're ready to go!
To install and run the application you'll need 2 simple steps:
From the project folder!
$ npm install
$ node server.js
To run tests
From the project folder!
$ npm test
Thats it, nows it's time to use the services!
Redirect to the URL registered for the :id
GET localhost:3005/urls/58defbbf96e87920900b63ce
Register a new URL for the :userid user
POST localhost:3005/users/jibao2
body: { "url": "https://github.com/anderson-amorim/URLake" }
Returns the new added URL as a JSON
{
"__v": 0,
"url": "https://github.com/anderson-amorim/URLake",
"_id": "58dffa23e61caf0af85e7e02",
"shortUrl": "localhost:3005/WIhWGI",
"user": {
"_id": "58dec85985e28324f49460bb",
"username": "jibao2",
"__v": 0,
"date": "2017-03-31T21:21:29.533Z"
},
"hits": 0,
"date": "2017-04-01T19:06:11.761Z"
}
Returns the general statistics of the system
GET localhost:3005/stats
{
"hits": 495,
"urlCount": 42,
"topUrls": [
{
"_id": "58defbbf96e87920900b63ce",
"url": "https://github.com/anderson-amorim/URLake",
"shortUrl": "localhost:3005/mfS1DI",
"user": "58dec85985e28324f49460bb",
"__v": 0,
"hits": 92,
"date": "2017-04-01T01:00:47.876Z"
},
{
"_id": "58defc2258e78031c424ad72",
"url": "https://github.com/anderson-amorim/URLake2222",
"shortUrl": "localhost:3005/aue2DI",
"user": "58dec85985e28324f49460bb",
"__v": 0,
"hits": 42,
"date": "2017-04-01T01:02:26.832Z"
}
...
]
}
Similar to stat, returns the general statistics of the :userId user
GET localhost:3005/users/jibao2
{
"hits": 135,
"urlCount": 8,
"topUrls": [
{
"_id": "58defbbf96e87920900b63ce",
"url": "https://github.com/anderson-amorim/URLake",
"shortUrl": "localhost:3005/mfS1DI",
"user": "58dec85985e28324f49460bb",
"__v": 0,
"hits": 92,
"date": "2017-04-01T01:00:47.876Z"
},
{
"_id": "58defc2258e78031c424ad72",
"url": "https://github.com/anderson-amorim/URLake2222",
"shortUrl": "localhost:3005/aue2DI",
"user": "58dec85985e28324f49460bb",
"__v": 0,
"hits": 42,
"date": "2017-04-01T01:02:26.832Z"
}
...
]
}
Returns the :id URL
GET localhost:3005/stats/58defbbf96e87920900b63ce
{
"_id": "58defbbf96e87920900b63ce",
"url": "https://github.com/anderson-amorim/URLake",
"shortUrl": "localhost:3005/mfS1DI",
"user": "58dec85985e28324f49460bb",
"__v": 0,
"hits": 92,
"date": "2017-04-01T01:00:47.876Z"
}
Delete the :id URL
DELETE localhost:3005/urls/58defbbf96e87920900b63ce
Add a new user
POST localhost:3005/users
body: { "username": "jibanelson" }
Returns the new added user
{
"__v": 0,
"username": "jibanelson",
"_id": "58dffe79cb20891180773746",
"date": "2017-04-01T19:24:41.615Z"
}
Delete the :userId user
DELETE localhost:3005/user/jibanelson