メインコンテンツにスキップ

CallOut

Call Out 🫵 is a free multiplayer web app designed to spice up your nights with friends through interactive voting like "Who among us is most likely to...". Developed using Google Apps Script and Firebase Realtime Database, it runs in real time without a dedicated backend server.

AI Summary

CallOut

A wrapper library that makes calling other scripts or Web APIs from Google Apps Script safe and concise.

Target Users

Intermediate-to-advanced Google Apps Script developers who integrate APIs or microservices and want a common, hassle-free way to handle external calls without worrying about authentication and error handling.

Problems Solved

Implementing authentication, retries, and exception handling every time you call an external service from Apps Script is tedious and slows development.

Tags

Main Features

1
Less Boilerplate

Set up authentication, headers, retry, and timeout logic in a single function call.

2
Unified Error Handling

Catches API errors centrally and re-throws them as custom exceptions, making branching in the caller clean.

3
Easy Testing & Mocking

Since the call logic is abstracted, you can swap in mock data and write unit tests easily.

Usage Examples

【Introduction】Run a simple GET request

// Library ID is already added
function quickGet() {
  // One-liner GET to an external API
  const response = CallOut.get('https://api.example.com/users');
  Logger.log(response);
}

Performs a simple GET and logs the raw response. No auth or headers needed if the API is open.

【Basic】POST with headers and timeout

function createUser() {
  const payload = {name: 'John'};
  const options = {
    method: 'post',
    headers: {Authorization: 'Bearer ' + ScriptProperties.getProperty('API_TOKEN')},
    muteHttpExceptions: true,
    timeout: 30 // seconds
  };
  const res = CallOut.fetch('https://api.example.com/users', payload, options);
  Logger.log(res.status); // status code
  Logger.log(res.body);   // JSON response
}

fetch lets you tweak method, headers, and timeout. The response comes back as an object for easy handling.

【Best Practice】Robust call with retry and mocking

function getOrder(orderId) {
  // Switch between prod and mock depending on environment
  const endpoint = PropertiesService.getScriptProperties().getProperty('ENV') === 'test'
      ? `https://mock.example.com/orders/${orderId}`
      : `https://api.example.com/orders/${orderId}`;

  const res = CallOut.fetchWithRetry(endpoint, {
    method: 'get',
    headers: {Authorization: 'Bearer ' + getServiceToken()},
    retries: 3,          // 3 retries
    backoff: 2           // 2-second exponential back-off
  });

  if (res.ok) {
    return JSON.parse(res.body);
  }
  throw new Error(`Order API failed: ${res.status}`);
}

fetchWithRetry automates retries and exponential back-off. Switching to a mock URL in tests keeps unit tests simple.