This API endpoint provides a proxy to fetch Medium post data using Medium’s GraphQL API with built-in caching.
Fetch a Medium post by its ID using query parameters.
Query Parameters:
postId (required): The Medium post IDcookies (optional): Medium cookies for authenticated requestsskipCache (optional): Set to true to bypass cache and fetch fresh data (default: false)Examples:
# Standard request (uses cache)
curl "http://localhost:4321/api/medium/post?postId=YOUR_POST_ID"
# Bypass cache
curl "http://localhost:4321/api/medium/post?postId=YOUR_POST_ID&skipCache=true"
# With authentication
curl "http://localhost:4321/api/medium/post?postId=YOUR_POST_ID&cookies=YOUR_COOKIES"Fetch a Medium post by its ID using JSON body.
Request Body:
{
"postId": "YOUR_POST_ID",
"cookies": "optional_cookies_string",
"skipCache": false
}Examples:
# Standard request (uses cache)
curl -X POST http://localhost:4321/api/medium/post \
-H "Content-Type: application/json" \
-d '{"postId":"YOUR_POST_ID"}'
# Bypass cache
curl -X POST http://localhost:4321/api/medium/post \
-H "Content-Type: application/json" \
-d '{"postId":"YOUR_POST_ID","skipCache":true}'{
"data": {
"post": {
"id": "...",
"title": "...",
"content": {...},
...
},
"meterPost": {...}
}
}400 Bad Request - Missing postId:
{
"error": "Missing required parameter: postId",
"usage": "GET /api/medium/post?postId=YOUR_POST_ID"
}500 Internal Server Error - Failed to fetch:
{
"error": "Failed to fetch post",
"postId": "..."
}500 Internal Server Error - Exception:
{
"error": "Internal server error",
"message": "error details"
}This API implements server-side caching using node-cache to improve performance and reduce load on Medium’s API.
post:{postId}post:{postId}:authskipCache=true to force fresh data fetchCache-Control: public, max-age=3600 - Instructs browsers to cache for 1 hourX-Cache-Status: HIT|BYPASS - Indicates whether cache was usedThis API route is a TypeScript/Astro implementation that replicates the functionality of the Python MediumApiService from the freedium-library. It:
The API uses these headers to mimic the Medium mobile app:
X-APOLLO-OPERATION-ID: Random SHA-256 hashX-APOLLO-OPERATION-NAME: “FullPostQuery”X-Client-Date: Current timestamp in millisecondsUser-Agent: “AdsBot-Google-Mobile”Content-Type: application/jsonCache-Control: public, max-age=3600X-Cache-Status: HIT|BYPASSMedium post IDs can be extracted from the Medium URL or from the post’s source code. The post ID is typically a hash string that looks like abc123def456.
Example Medium URL:
https://medium.com/@username/article-title-abc123def456The post ID would be: abc123def456