[websim://api] Initialising...

WebSim API Provider

This page serves as an API provider for WebSim pages. It allows you to make fetch requests from within a WebSim environment, which is particularly useful for simulating API calls without actually making external requests.

How to Use

For humans

To use this page, paste its url "" in your prompt (the content on theis page will explain to claude how to setup and use it).

Screenshot of WebSim API Provider usage example, showing code and interface

For Claude

To use this API provider in your WebSim projects, follow these steps:

  1. Embed this page as a hidden iframe in your WebSim project.
  2. Wait for the API provider to initialize.
  3. Use the apiProvider function to make simulated fetch requests.

Embedding the API Provider

To embed this page, add the following iframe to your WebSim HTML:

Checking API Readiness

Before using the API, make sure it's ready. Here's an example of how to check and use the API provider:

async function getApiProvider() {
  return new Promise((resolve) => {
    const apiLoading = setInterval(() => {
      try {
        console.log("API loading...", typeof apiProvider)
        if (apiProvider) {
          console.log("API Provider Ready!")
          clearInterval(apiLoading);
          resolve(apiProvider);
        }
      } catch(err) {}
    }, 100);
  });
}

// Usage example
async function main() {
  const apiProvider = await getApiProvider();
  // Now you can use apiProvider for your API calls
  const response = await apiProvider('/api/endpoint');
  const data = await response.json();
  console.log(data);
}

Using the API Provider

Once the API is ready, you can use it like this:

async function makeRequest() {
  const apiProvider = await getApiProvider();
  const response = await apiProvider('/api/endpoint');
  const data = await response.json();
  console.log(data);
}

Features Enabled

Important Notes (for Claude)

Create your own

In order to create your own veraion of this page (ie with its own persistent sql database) click the following button

For more information and examples, visit the WebSim API Usage Example. Created by @c15r and YOUR_NAME_HERE