Back to Home

Documentation

API Reference

Create and retrieve snippets programmatically.

Base URL

https://pastecn.com/api/v1

Authentication

Password-protected snippets require Bearer token authentication. Include the password in the Authorization header.

Authorization: Bearer <password>

Public snippets do not require authentication.

POST

/snippets

Create a new snippet. The ID is generated server-side.

Request Body

{
  "name": "my-component",
  "type": "component",
  "files": [
    {
      "path": "components/my-component.tsx",
      "content": "export function MyComponent() {\n  return <div>Hello</div>\n}"
    }
  ],
  "password": "optional-password"
}

Response

201 Created
{
  "id": "xK9mN2pL",
  "url": "https://pastecn.com/p/xK9mN2pL",
  "registryUrl": "https://pastecn.com/r/xK9mN2pL",
  "password": "generated-password"
}

Example

terminal
$curl -X POST https://pastecn.com/api/v1/snippets \ -H "Content-Type: application/json" \ -d '{"name":"my-component","type":"component","files":[{"path":"components/button.tsx","content":"export const Button = () => <button>Click</button>"}]}'
GET

/snippets/{id}

Retrieve a snippet by ID. Protected snippets require Bearer authentication.

Response

200 OK
{
  "id": "xK9mN2pL",
  "name": "my-component",
  "type": "component",
  "files": [
    {
      "path": "components/my-component.tsx",
      "content": "export function MyComponent() {...}",
      "language": "tsx"
    }
  ],
  "meta": {
    "primaryLanguage": "tsx",
    "fileCount": 1
  },
  "isProtected": false
}

Example (Public Snippet)

terminal
$curl https://pastecn.com/api/v1/snippets/xK9mN2pL

Example (Protected Snippet)

terminal
$curl https://pastecn.com/api/v1/snippets/xK9mN2pL \ -H "Authorization: Bearer your-password"

Snippet Types

The type field determines how the snippet is registered in the shadcn registry.

file

Miscellaneous files. Config files, types, or any other file.

component

React components. Single-file UI elements.

hook

React hooks. Custom state management or side effects.

lib

Utility functions and helpers. Pure logic, no UI.

block

Complex components with multiple files. Combines components, hooks, utils, and types into a complete feature.

Error Codes

All errors return a JSON response with a code and message field.

{
  "code": "NOT_FOUND",
  "message": "Snippet not found"
}
CodeHTTPDescription
VALIDATION_ERROR400Invalid request body or parameters
INVALID_ID400Snippet ID format is invalid
AUTH_REQUIRED401Protected snippet requires Bearer token
INVALID_PASSWORD401Bearer token does not match password
NOT_FOUND404Snippet does not exist
ID_COLLISION409Generated ID already exists (retry)
RATE_LIMITED429Too many requests
INTERNAL_ERROR500Server error