Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/suzukiryuichiro/url-shortner
https://github.com/suzukiryuichiro/url-shortner
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/suzukiryuichiro/url-shortner
- Owner: SuzukiRyuichiro
- Created: 2022-11-26T17:18:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-27T23:29:50.000Z (about 2 years ago)
- Last Synced: 2024-11-09T09:39:45.871Z (about 2 months ago)
- Language: JavaScript
- Size: 101 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Local setup
- Install docker if not
run
```
docker compose up --build
```once build is done
```
curl http://localhost:8080/ping
```-> should return `pong`
# End points
## `POST /` - Get a shortened URL
Give a long URL to get a shortened URL
## Body
```json
{
"url": "https://www.google.com" // required
}
```## Response
200
```json
{
"url": "http://localhost:8080/bMoYt2Nx2"
}
```400
```json
{
"error": "Invalid URL"
}
```## `POST /` - Retrieve original URL
Give one of the shortened URL to see what was the original URL
## Body
```json
{
"url": "http://localhost:8080/bMoYt2Nx2" // required
}
```## Responses
200
Found
```json
{
"url": "https://www.google.com"
}
```400
URL format is wrong
```json
{
"error": "Invalid URL"
}
```404
There is no record of given URL
```json
{
"error": "Could not find the URL"
}
```# Reasons of the stack
- I chose redis for database since URL shortener only requires a simple database that doesn't have relations between models. Given it's fastness and scalability, I chose redis.
- I chose Node as the frame work since I knew the logic of the app would be fairly simple, so I wanted to use something that I know I can write and something that does not have much boilerplate code to over complicate the app. Also, I chose Node since the community is large and I knew I would be able to find necessary libraries for the development.
- I used docker so it'd be simpler to test the API on other machines as well.