Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajaysinghj8/shorty
https://github.com/ajaysinghj8/shorty
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ajaysinghj8/shorty
- Owner: ajaysinghj8
- Created: 2019-10-12T11:54:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T00:42:00.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T05:56:31.819Z (7 months ago)
- Language: JavaScript
- Size: 147 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Shorty Challenge
================## The Challenge
The challenge, if you choose to accept it, is to create a micro service to shorten urls, in the style that TinyURL and bit.ly made popular.
## Acceptance Criteria
1. The service must expose HTTP endpoints according to the definition below.
2. The service must be self contained in a Docker image, but it must be possible to set it up from a fresh install of Ubuntu Server latest LTS, by following the steps you write in the README.
3. It must be well tested, it must also be possible to run the entire test suit with a single command from the directory of your repository.
4. The service must be versioned using git and git history **should** be meaningful.
5. You don't have to use a datastore, you can have all data in memory, but you are free if you wanto do use one.## Tips
* Less is more, small is beautiful, you know the drill — stick to the requirements.
* Use the right tool for the job.
* No need to take care of domains, that's for a reverse proxy to handle.
* Unit tests > Integration tests, but be careful with untested parts of the system.**Good Luck!** — not that you need any ;)
-------------------------------------------------------------------------
## API Documentation
**All responses must be encoded in JSON and have the appropriate Content-Type header**
### POST /shorten
```
POST /shorten
Content-Type: "application/json"{
"url": "http://example.com",
"shortcode": "example"
}
```Attribute | Description
--------- | -----------
**url** | url to shorten
shortcode | preferential shortcode##### Returns:
```
201 Created
Content-Type: "application/json"{
"shortcode": :shortcode
}
```A random shortcode is generated if none is requested, the generated short code has exactly 6 alpahnumeric characters and passes the following regexp: ```^[0-9a-zA-Z_]{6}$```.
##### Errors:
Error | Description
----- | ------------
400 | ```url``` is not present
409 | The the desired shortcode is already in use. **Shortcodes are case-sensitive**.
422 | The shortcode fails to meet the following regexp: ```^[0-9a-zA-Z_]{4,}$```.### GET /:shortcode
```
GET /:shortcode
Content-Type: "application/json"
```Attribute | Description
-------------- | -----------
**shortcode** | url encoded shortcode##### Returns
**302** response with the location header pointing to the shortened URL
```
HTTP/1.1 302 Found
Location: http://www.example.com
```##### Errors
Error | Description
----- | ------------
404 | The ```shortcode``` cannot be found in the system### GET /:shortcode/stats
```
GET /:shortcode/stats
Content-Type: "application/json"
```Attribute | Description
-------------- | -----------
**shortcode** | url encoded shortcode##### Returns
```
200 OK
Content-Type: "application/json"{
"startDate": "2012-04-23T18:25:43.511Z",
"lastSeenDate": "2012-04-23T18:25:43.511Z",
"redirectCount": 1
}
```Attribute | Description
-------------- | -----------
**startDate** | date when the url was encoded, conformant to [ISO8601](http://en.wikipedia.org/wiki/ISO_8601)
**redirectCount** | number of times the endpoint ```GET /shortcode``` was called
lastSeenDate | date of the last time the a redirect was issued, not present if ```redirectCount == 0```##### Errors
Error | Description
----- | ------------
404 | The ```shortcode``` cannot be found in the system