📋 Code Snippet Manager — API Documentation

API Reference

Base URL: https://api.codesnippet-manager.example.com/v1

Authentication

POST /auth/register

Register a new user account.

Request Body:

{
  "email": "user@example.com",
  "password": "securepassword123",
  "username": "johndoe"
}

Response (201 Created):

{
  "id": "usr_abc123",
  "email": "user@example.com",
  "username": "johndoe",
  "created_at": "2026-01-15T10:30:00Z"
}

POST /auth/login

Authenticate and receive JWT token.

Request Body:

{
  "email": "user@example.com",
  "password": "securepassword123"
}

Response (200 OK):

{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "token_type": "Bearer",
  "expires_in": 3600
}

Snippets

GET /snippets

Retrieve a list of all snippets for the authenticated user.

Query Parameters: | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | page | integer | 1 | Page number | | limit | integer | 20 | Items per page (max: 100) | | language | string | - | Filter by language | | tag | string | - | Filter by tag | | sort | string | created_at | Sort field (created_at, updated_at, title) | | order | string | desc | Sort order (asc, desc) |

Response (200 OK):

{
  "data": [
    {
      "id": "snip_xyz789",
      "title": "React useEffect Hook",
      "content": "useEffect(() => {\n  console.log('Mounted');\n}, []);",
      "language": "javascript",
      "tags": ["react", "hooks"],
      "description": "Basic useEffect example",
      "is_public": false,
      "created_at": "2026-01-15T10:30:00Z",
      "updated_at": "2026-01-15T10:30:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 45,
    "total_pages": 3
  }
}

GET /snippets/:id

Retrieve a specific snippet by ID.

Path Parameters: | Parameter | Type | Description | |-----------|------|-------------| | id | string | Snippet ID |

Response (200 OK):

{
  "id": "snip_xyz789",
  "title": "React useEffect Hook",
  "content": "useEffect(() => {\n  console.log('Mounted');\n}, []);",
  "language": "javascript",
  "tags": ["react", "hooks"],
  "description": "Basic useEffect example",
  "is_public": false,
  "created_at": "2026-01-15T10:30:00Z",
  "updated_at": "2026-01-15T10:30:00Z",
  "owner": {
    "id": "usr_abc123",
    "username": "johndoe"
  }
}

Response (404 Not Found):

{
  "error": {
    "code": "SNIPPET_NOT_FOUND",
    "message": "Snippet with ID 'snip_xyz789' not found"
  }
}

POST /snippets

Create a new snippet.

Request Body:

{
  "title": "React useEffect Hook",
  "content": "useEffect(() => {\n  console.log('Mounted');\n}, []);",
  "language": "javascript",
  "tags": ["react", "hooks"],
  "description": "Basic useEffect example",
  "is_public": false
}

Response (201 Created):

{
  "id": "snip_xyz789",
  "title": "React useEffect Hook",
  "content": "useEffect(() => {\n  console.log('Mounted');\n}, []);",
  "language": "javascript",
  "tags": ["react", "hooks"],
  "description": "Basic useEffect example",
  "is_public": false,
  "created_at": "2026-01-15T10:30:00Z",
  "updated_at": "2026-01-15T10:30:00Z"
}

PUT /snippets/:id

Update an existing snippet.

Request Body:

{
  "title": "Updated Title",
  "content": "Updated content here",
  "language": "typescript",
  "tags": ["react", "hooks", "updated"],
  "description": "Updated description",
  "is_public": true
}

Response (200 OK):

{
  "id": "snip_xyz789",
  "title": "Updated Title",
  "content": "Updated content here",
  "language": "typescript",
  "tags": ["react", "hooks", "updated"],
  "description": "Updated description",
  "is_public": true,
  "created_at": "2026-01-15T10:30:00Z",
  "updated_at": "2026-01-15T11:45:00Z"
}

DELETE /snippets/:id

Delete a snippet.

Response (204 No Content): Empty response body.


Search

GET /snippets/search

Search snippets by keyword.

Query Parameters: | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | q | string | Yes | Search query | | language | string | No | Filter by language | | tag | string | No | Filter by tag | | page | integer | No | Page number (default: 1) | | limit | integer | No | Items per page (default: 20) |

Response (200 OK):

{
  "data": [
    {
      "id": "snip_xyz789",
      "title": "React useEffect Hook",
      "content": "useEffect(() => {\n  console.log('Mounted');\n}, []);",
      "language": "javascript",
      "tags": ["react", "hooks"],
      "highlight": {
        "title": "<em>React</em> useEffect Hook",
        "content": "<em>useEffect</em>(() => {\n  console.log('Mounted');\n}, []);"
      }
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 12,
    "total_pages": 1
  }
}

Languages

GET /languages

Get list of supported programming languages.

Response (200 OK):

{
  "data": [
    {"id": "javascript", "name": "JavaScript", "icon": "js"},
    {"id": "python", "name": "Python", "icon": "py"},
    {"id": "typescript", "name": "TypeScript", "icon": "ts"},
    {"id": "java", "name": "Java", "icon": "java"},
    {"id": "go", "name": "Go", "icon": "go"},
    {"id": "rust", "name": "Rust", "icon": "rust"}
  ]
}

Tags

GET /tags

Get all tags used by the authenticated user.

Response (200 OK):

{
  "data": [
    {"name": "react", "count": 15},
    {"name": "hooks", "count": 8},
    {"name": "python", "count": 12},
    {"name": "api", "count": 5}
  ]
}

Public Snippets

GET /public/snippets

Browse public snippets from all users.

Query Parameters: | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | page | integer | 1 | Page number | | limit | integer | 20 | Items per page | | language | string | - | Filter by language | | tag | string | - | Filter by tag |

Response (200 OK):

{
  "data": [
    {
      "id": "snip_public123",
      "title": "Python List Comprehension",
      "content": "squares = [x**2 for x in range(10)]",
      "language": "python",
      "tags": ["python", "list"],
      "owner": {
        "username": "pydev"
      },
      "created_at": "2026-01-14T08:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 150,
    "total_pages": 8
  }
}

User Profile

GET /users/me

Get current user profile.

Response (200 OK):

{
  "id": "usr_abc123",
  "email": "user@example.com",
  "username": "johndoe",
  "plan": "pro",
  "snippet_count": 45,
  "created_at": "2026-01-01T00:00:00Z"
}

PATCH /users/me

Update user profile.

Request Body:

{
  "username": "newusername",
  "email": "newemail@example.com"
}

Response (200 OK):

{
  "id": "usr_abc123",
  "email": "newemail@example.com",
  "username": "newusername",
  "updated_at": "2026-01-15T12:00:00Z"
}