Course Content
Data Structures & Algorithms
Full Stack Web Development
Understanding and playing with DOM (Document Object Model)
0/2
MERN project
0/2
Low Level System Design
LLD Topics
High Level System Design
Fast-Track to Full Spectrum Software Engineering
System APIs of Pastebin

When designing a Pastebin system, APIs (Application Programming Interfaces) play a central role in enabling interactions between users, the front-end, and the back-end services. These APIs will facilitate operations like creating pastes, retrieving pastes, deleting them, and managing user preferences. Below is an outline of the essential System APIs for a Pastebin application that you can explain to your students.



1. API for Creating a Paste

Endpoint: POST /api/paste

 

  • Description: This API endpoint allows users to create a new paste by submitting content (text or code) to the system. The system will store the content and generate a unique URL for the paste.

 

Request Parameters:

 

  • content (string): The text or code to be pasted.
  • title (optional, string): The title for the paste (e.g., “Sample Python Code”).
  • language (optional, string): The programming language for syntax highlighting (e.g., “python”, “javascript”).
  • visibility (optional, string): Defines if the paste is public or private.
  • expire_in (optional, string): Time to live for the paste (e.g., “7 days”, “1 hour”).

 

Response:

 

  • paste_url (string): A URL that can be shared with others to access the paste.
  • status (string): The status of the operation (e.g., “success”).
  • paste_id (string): The unique identifier for the paste.

 

Example Request:
{
"content": "def hello_world():n print('Hello, World!')",
"language": "python",
"visibility": "public",
"expire_in": "7 days"
}
Example Response:
{
"status": "success",
"paste_url": "https://pastebin.com/abc123xyz",
"paste_id": "abc123xyz"
}

 

2. API for Retrieving a Paste

Endpoint: GET /api/paste/{paste_id}

 

  • Description: This API endpoint allows users to retrieve a specific paste using its unique paste_id. It will return the content of the paste along with metadata such as language and creation time.

 

Request Parameters:

 

  • paste_id (path parameter): The unique identifier of the paste to retrieve.

 

Response:

 

  • content (string): The text or code content stored in the paste.
  • language (string): The programming language associated with the paste (e.g., “python”).
  • title (string, optional): The title of the paste.
  • created_at (string): Timestamp of when the paste was created.
  • expires_at (string): Timestamp of when the paste expires.

 

Example Request:
GET /api/paste/abc123xyz
Example Response:
{
"content": "def hello_world():n print('Hello, World!')",
"language": "python",
"title": "Sample Python Code",
"created_at": "2025-03-01T10:00:00Z",
"expires_at": "2025-03-08T10:00:00Z"
}

 

3. API for Deleting a Paste

Endpoint: DELETE /api/paste/{paste_id}

 

  • Description: This API allows users to delete a specific paste by its paste_id. It removes both the content and metadata associated with the paste from the system.

 

Request Parameters:

 

  • paste_id (path parameter): The unique identifier of the paste to delete.

 

Response:

 

  • status (string): The status of the operation (e.g., “success”, “not found”).

 

Example Request:
DELETE /api/paste/abc123xyz
Example Response:
{
"status": "success"
}

 

4. API for Listing User Pastes

Endpoint: GET /api/user/pastes

 

  • Description: This API endpoint retrieves a list of all pastes created by the authenticated user. The user can fetch metadata like titles and creation timestamps of their pastes.

 

Request Parameters:

 

  • user_id (query parameter): The unique identifier of the user (if not authenticated through a session).
  • limit (optional, integer): The number of pastes to retrieve in one request.
  • offset (optional, integer): The page number or offset to start fetching from.

 

Response:

 

  • pastes (array): An array of paste objects, each containing metadata.
  • paste_id (string): Unique identifier of the paste.
  • title (string): The title of the paste.
  • created_at (string): Timestamp when the paste was created.

 

Example Request:
GET /api/user/pastes?user_id=12345&limit=10
Example Response:
{
"pastes": [
{
"paste_id": "abc123xyz",
"title": "Sample Python Code",
"created_at": "2025-03-01T10:00:00Z"
},
{
"paste_id": "xyz456abc",
"title": "Debugging Log",
"created_at": "2025-03-02T12:00:00Z"
}
]
}

 

5. API for Managing Paste Expiration

Endpoint: POST /api/paste/expire/{paste_id}

 

  • Description: This API allows users to set or modify the expiration time of an existing paste. The paste will be deleted once it expires.

 

Request Parameters:

  • paste_id (path parameter): The unique identifier of the paste to modify.
  • expire_in (string): Time duration after which the paste will expire (e.g., “1 hour”, “30 days”).

 

Response:

 

  • status (string): The status of the operation (e.g., “success”).
  • expire_at (string): The new expiration timestamp.

 

Example Request:
{
"expire_in": "5 days"
}
Example Response:
{
"status": "success",
"expire_at": "2025-03-06T10:00:00Z"
}

 

6. API for Searching Pastes

Endpoint: GET /api/search

 

  • Description: This API allows users to search for pastes based on a query string. It is useful for finding pastes with certain keywords, titles, or content.

 

Request Parameters:

 

  • query (query parameter): The search term to look for in the paste content or title.
  • limit (optional, integer): The number of results to return.
  • offset (optional, integer): The page number or offset to start fetching from.

 

Response:

 

  • results (array): A list of pastes that match the search query.
  • paste_id (string): Unique identifier of the paste.
  • title (string): Title of the paste.
  • created_at (string): Timestamp when the paste was created.

 

Example Request:
GET /api/search?query=python&limit=5
Example Response:
{
"results": [
{
"paste_id": "abc123xyz",
"title": "Python Code for Sorting",
"created_at": "2025-03-01T10:00:00Z"
},
{
"paste_id": "xyz456abc",
"title": "Python Debugging Tips",
"created_at": "2025-03-02T12:00:00Z"
}
]
}

 

7. API for User Authentication (Optional)

Endpoint: POST /api/auth/login

 

  • Description: This API allows users to authenticate with their username and password, returning a token for session management.

 

Request Parameters:

 

  • username (string): The user’s username.
  • password (string): The user’s password.

 

Response:

 

  • token (string): A session token to authenticate further requests.
  • status (string): The status of the operation (e.g., “success”).

 

Example Request:
{
"username": "user123",
"password": "password123"
}
Example Response:
{
"status": "success",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjM0NTY3ODkwLCJleHBpcmVkX2F0IjoiMjAyNS0wMy0wMVQxMjo1NzowMFoifQ.Gj9sos2jGOGhQXJlCEqVJWpHpnvPO3F4ghKmxyerjxY"
}


Conclusion

These System APIs for a Pastebin system allow users to interact with the application in a structured and predictable way. These APIs provide basic operations such as creating, retrieving, updating, and deleting pastes, along with the ability to manage user-specific data, expiration times, and privacy settings. By explaining these APIs, students can better understand the core functions of a web service and how RESTful APIs work in a real-world application.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.