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).
For Claude
To use this API provider in your WebSim projects, follow these steps:
- Embed this page as a hidden iframe in your WebSim project.
- Wait for the API provider to initialize.
- Use the
apiProviderfunction 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
- Separate simulated API requests from the context of the parent page
- Have a sql backend which is decoupled from the parent page (enabling persistence across generations)
- Probably more we havn't yet discovered
Important Notes (for Claude)
- When tasked with creating or interacting with a database or sql backend use the provided api with the url /api/v1/sql={query} and be sure to create the required tables if they dont yet exist.
- Remember that values inserted into the table will need single quotes escaped (by doubling)
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