Published on
An Avestura Project:

PasteBin

Authors

Paste Bin

Avestura's PasteBin is a modern paste bin with RESTful API

Visit Project Here: Avestura's Paste Bin

Stack used: React, Next, Blueprint, MinIO S3 Object Storage, and Redis for rate-limiting (fallbacks to memory if it fails)

Env Vars for Self-hosting

MINIO_ENDPOINT=
MINIO_ACCESS_KEY=
MINIO_SECRET_KEY=
REDIS_ENDPOINT=
REDIS_PORT=
REDIS_PASSWORD=

API

Submit a new Paste

Creates a new paste in the Avestura's Paste Bin

Body:

  • name: string # Id of the paste that appears in the url
  • doc: string # Content of the paste
  • language: string # Programming language of the paste
  • owner?: optional uuid string # UUID of creator
http
POST /api/paste

{
    name: "my-paste",
    doc: "const id = x => x;",
    language: "javascript",
    owner: "5777c422-0ea1-4d07-8e8d-163f4484c9dc"
}

Delete a paste

Deletes the paste and frees the reserved paste name. The creator of the paste has 60 minutes to delete the paste after creation.

Body:

  • pasteId: string # Id of the paste to be deleted
  • owner: uuid string # Owner Id
http
DELETE /api/paste

{
    name: "my-paste",
    owner: "5777c422-0ea1-4d07-8e8d-163f4484c9dc"
}

Name Availability

Checks if a name is already taken or not.

Query:

  • name: string # A name to check availability

Returns:

  • status: "taken" | "available" | "error" # The status of the input name
http
GET /api/paste/checkexists?name=INPUT_NAME

Get Paste with meta data

Get paste content, last modified data, language, and content size in bytes.

http
GET /api/paste/:pasteId

Output sample:

json
{
  "language": "javascript",
  "body": "const id = x => x;",
  "lastModified": "2021-08-20T09:28:04.000Z",
  "size": 18
}

Get paste raw content

Get paste's raw content, with text/plain content-type.

http
GET /api/paste/:pasteId?raw

Get paste as module

Get paste's raw content as module with accurate content-type if the programming language is one of the languages listed below. This will come in handy if you want to import the paste remotely in a runtime like Deno. Content type listing:

  • JavaScript: text/javascript
  • TypeScript: application/typescript
  • Python: text/x-python
  • F#: text/fsharp
  • CSS: text/css
  • JSON: application/json
  • Yaml: text/x-yaml
  • Markdown: text/markdown
  • XML: application/xml

For any other language, including HTML, content-type will be text/plain, so it's better to use ?raw instead of ?module for those pastes.

http
GET /api/paste/:pasteId?module

Usage sample:

javascript
import Something from "https://www.avestura.dev/api/paste/sample-paste?module"

Tags

pastereactnext