Course contentsShow
← System Design
Lesson 1546 of 1,91938. Real-World System: PastebinFree lesson

API Design for Paste Operations

Designing REST endpoints for creating pastes, retrieving by key, and handling optional parameters.

API Design for Paste Operations

You'll learn how to design clean, intuitive REST endpoints that support the core functionality of a Pastebin service—creating pastes, retrieving them by key, and handling optional features like expiration and custom URLs.

Core Idea

A Pastebin's API serves as the contract between clients and your system. Since Pastebin is read-heavy (as discussed in traffic estimation), your API must optimize for fast, efficient retrieval while still supporting flexible paste creation. The design should be RESTful, predictable, and scalable.

Essential Endpoints

Creating a Paste

POST /api/v1/pastes

Request body:

{
  "content": "paste text here",
  "expirationTime": "2024-12-31T23:59:59Z",  // optional
  "customKey": "myPaste123",                  // optional
  "isPrivate": false                          // optional
}

Response: Returns the generated paste key (or confirms custom key) and full URL.

Retrieving a Paste

GET /api/v1/pastes/{pasteKey}

Returns the paste content, metadata (creation time, expiration), and view count. This is your highest-traffic endpoint—design for caching and speed.

Optional Parameters

Support query parameters for filtering:

  • ?format=json or ?format=raw (content-type negotiation)
  • ?syntax=python (syntax highlighting hint for clients)

Design Considerations

Like the URL shortener schema, your API should handle custom keys, expiration times, and private/public visibility. These optional parameters give users flexibility without complicating the basic use case—just paste and share.

Key Takeaway: Design RESTful endpoints that prioritize simplicity for common operations (POST to create, GET to retrieve) while supporting optional parameters for advanced features like custom keys and expiration policies.