Skip to content

Latest commit

 

History

History
140 lines (99 loc) · 2.21 KB

README.md

File metadata and controls

140 lines (99 loc) · 2.21 KB

short

A short url service.

Online Services

Getting Started

$ 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

Deploy with Vercel

Endpoints

POST /create

Create a new short url.

$ 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

{
  "slug": "<slug>",
  "link": "http://t.zce.me/<slug>"
}

REST API Test

Bad request

POST http://localhost:3000/create HTTP/1.1

# {
#   "error": "Bad Request",
#   "message": "Illegal body: unexpected end of JSON input."
# }

No parameters

POST http://localhost:3000/create HTTP/1.1
content-type: application/json

{}

# {
#   "error": "Bad Request",
#   "message": "Missing required parameter: url."
# }

Request with url parameter

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

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

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 © zce