https://github.com/zce/short
A short url service.
https://github.com/zce/short
Last synced: about 1 year ago
JSON representation
A short url service.
- Host: GitHub
- URL: https://github.com/zce/short
- Owner: zce
- License: mit
- Created: 2021-03-03T12:47:45.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-10T01:16:15.000Z (over 1 year ago)
- Last Synced: 2025-01-08T09:51:34.663Z (about 1 year ago)
- Language: HTML
- Homepage: https://t.zce.me
- Size: 83 KB
- Stars: 12
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# short
> A short url service.
## Online Services
- https://zvu.cc
- https://t.zce.me
## Getting Started
```shell
$ git clone https://github.com/zce/short.git
$ cd short
$ cp .env.example .env
$ vi .env # add your upstash redis url & token
$ npm install
$ npm run develop
```
### Environment Variables
- `UPSTASH_REDIS_REST_URL`: Upstash redis rest url.
- `UPSTASH_REDIS_REST_TOKEN`: Upstash redis rest token.
### Deploy
[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fzce%2Fshort&project-name=my-short&repository-name=my-short&integration-ids=oac_V3R1GIpkoJorr6fqyiwdhl17)
## Endpoints
### POST `/create`
Create a new short url.
```shell
$ curl https://t.zce.me/create -d "url=https://zce.me" -d "slug=zce"
```
#### Parameters
- `url`: target url
- `slug`: short slug, optional, default: `auto nanoid`
#### Response Type
```json
{
"slug": "",
"link": "http://t.zce.me/"
}
```
## REST API Test
### Bad request
```http
POST http://localhost:3000/create HTTP/1.1
# {
# "error": "Bad Request",
# "message": "Illegal body: unexpected end of JSON input."
# }
```
### No parameters
```http
POST http://localhost:3000/create HTTP/1.1
content-type: application/json
{}
# {
# "error": "Bad Request",
# "message": "Missing required parameter: url."
# }
```
### Request with url parameter
```http
POST http://localhost:3000/create HTTP/1.1
content-type: application/json
{
"url": "https://www.google.com"
}
# {
# "slug": "bPVp",
# "link": "http://localhost:3000/bPVp"
# }
```
### Request with url & slug parameters
```http
POST http://localhost:3000/create HTTP/1.1
content-type: application/json
{
"url": "https://www.google.com",
"slug": "google"
}
# {
# "slug": "google",
# "link": "http://localhost:3000/google"
# }
```
### Request with url & exist slug parameters
```http
POST http://localhost:3000/create HTTP/1.1
content-type: application/json
{
"url": "https://www.google1.com",
"slug": "google"
}
```
# {
# "error": "Bad Request",
# "message": "Slug already exists."
# }
```
### Redirect to url
```http
GET http://localhost:3000/google HTTP/1.1
```
## License
[MIT](LICENSE) © [zce](https://zce.me)