or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

blog-content.mdclient-configuration.mdcontent-discovery.mdhttp-requests.mdindex.mdpost-management.mdsocial-interactions.mduser-management.md
tile.json

http-requests.mddocs/

HTTP Request Methods

Low-level HTTP request methods for direct API access and custom endpoints not covered by higher-level methods.

Capabilities

GET Request

Performs HTTP GET requests to Tumblr API endpoints.

/**
 * Performs a GET request
 * @param apiPath - URL path for the request (e.g., '/v2/blog/myblog/info')
 * @param params - Query parameters as object
 * @returns Promise resolving to API response
 */
getRequest(apiPath: string, params?: Record<string, any>): Promise<any>;

Usage Examples:

// Get blog info with parameters
const blogInfo = await client.getRequest('/v2/blog/staff/info', {
  'fields[blogs]': 'name,title,description'
});

// Get posts with query parameters
const posts = await client.getRequest('/v2/blog/staff/posts', {
  type: 'photo',
  limit: 10,
  offset: 0
});

// Array parameters are automatically formatted
const taggedPosts = await client.getRequest('/v2/tagged', {
  tag: ['cats', 'funny']  // Becomes tag[0]=cats&tag[1]=funny
});

POST Request

Performs HTTP POST requests to Tumblr API endpoints.

/**
 * Performs a POST request
 * @param apiPath - URL path for the request
 * @param params - Request body parameters
 * @returns Promise resolving to API response
 */
postRequest(apiPath: string, params?: Record<string, any>): Promise<any>;

Usage Examples:

// Create a legacy post
const newPost = await client.postRequest('/v2/blog/myblog/post', {
  type: 'text',
  title: 'Hello World',
  body: 'This is my first post!'
});

// Like a post
await client.postRequest('/v2/user/like', {
  id: '12345',
  reblog_key: 'abc123'
});

// Follow a blog
await client.postRequest('/v2/user/follow', {
  url: 'example.tumblr.com'
});

PUT Request

Performs HTTP PUT requests to Tumblr API endpoints.

/**
 * Performs a PUT request
 * @param apiPath - URL path for the request
 * @param params - Request body parameters
 * @returns Promise resolving to API response
 */
putRequest(apiPath: string, params?: Record<string, any>): Promise<any>;

Usage Examples:

// Edit a post
await client.putRequest('/v2/blog/myblog/posts/12345', {
  content: [
    {
      type: 'text',
      text: 'Updated post content'
    }
  ]
});

Request Processing Details

Parameter Handling

Different parameter handling based on request method and content type:

GET Requests:

  • All parameters converted to query string
  • Arrays formatted as param[0]=value1&param[1]=value2
  • Objects flattened to key-value pairs

POST/PUT Requests:

  • Parameters sent in request body
  • JSON encoding for simple data
  • Multipart/form-data for media uploads

Content Type Detection

The client automatically determines content type based on parameters:

// JSON content-type (application/json)
await client.postRequest('/v2/blog/myblog/post', {
  type: 'text',
  title: 'Simple post'
});

// Multipart content-type (multipart/form-data)
await client.postRequest('/v2/blog/myblog/posts', {
  json: JSON.stringify({ content: [...] }),
  0: fs.createReadStream('image.jpg')  // Media upload
});

Authentication Integration

HTTP methods automatically apply authentication based on client configuration:

// API key authentication (query parameter)
const apiKeyClient = tumblr.createClient({ consumer_key: 'key' });
await apiKeyClient.getRequest('/v2/blog/staff/info');
// Requests: GET /v2/blog/staff/info?api_key=key

// OAuth authentication (Authorization header)
const oauthClient = tumblr.createClient({
  consumer_key: 'key',
  consumer_secret: 'secret',
  token: 'token',
  token_secret: 'token_secret'
});
await oauthClient.postRequest('/v2/user/info');
// Includes: Authorization: OAuth oauth_consumer_key="key", oauth_signature="...", ...

Request Headers

All requests include standard headers:

{
  'User-Agent': 'tumblr.js/5.0.1',
  'Accept': 'application/json',
  'Content-Type': 'application/json' | 'multipart/form-data'  // Based on content
}

Array Parameter Formatting

Arrays are automatically formatted for Tumblr API expectations:

// Input
await client.getRequest('/v2/tagged', {
  tag: ['cats', 'funny', 'gifs']
});

// Query string
// ?tag[0]=cats&tag[1]=funny&tag[2]=gifs

// Post body arrays
await client.postRequest('/v2/blog/myblog/posts', {
  tags: ['technology', 'programming']
});

// Form data
// tags[0]=technology
// tags[1]=programming

Error Handling

HTTP methods handle various error conditions:

try {
  const result = await client.getRequest('/v2/blog/nonexistent/info');
} catch (error) {
  // API errors
  console.log(error.message); // "API error: 404 Not Found"
}

try {
  const result = await client.postRequest('/v2/invalid-endpoint');
} catch (error) {
  // Network errors, parsing errors, etc.
  console.log(error.message);
}

URL Construction

API paths are automatically combined with the client's base URL:

const client = tumblr.createClient({
  baseUrl: 'https://api.tumblr.com'  // Default
});

// apiPath: '/v2/blog/staff/info'
// Full URL: https://api.tumblr.com/v2/blog/staff/info
await client.getRequest('/v2/blog/staff/info');

Media Upload Support

POST and PUT requests support media uploads via Node.js streams:

const fs = require('fs');

await client.postRequest('/v2/blog/myblog/posts', {
  json: JSON.stringify({
    content: [
      {
        type: 'image',
        media: { identifier: '0' },
        alt_text: 'My photo'
      }
    ]
  }),
  0: fs.createReadStream('./photo.jpg')  // Stream mapped to identifier
});

Legacy Callback Support

All HTTP methods support legacy callback patterns (deprecated):

// Promise (recommended)
const result = await client.getRequest('/v2/blog/staff/info');

// Callback (deprecated)
client.getRequest('/v2/blog/staff/info', (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log(result);
  }
});

// Callback with parameters (deprecated)
client.getRequest('/v2/blog/staff/posts', { limit: 5 }, (err, result) => {
  // Handle response
});