### Get a subdomain Source: https://docs.puter.com/Hosting/get/index This example demonstrates how to create a new website, retrieve its details using puter.hosting.get(), and then clean up by deleting the website. It requires the Puter JavaScript SDK to be included. ```html ``` -------------------------------- ### Get an App by Name Source: https://docs.puter.com/Apps/get/index This example demonstrates how to create a random app, then retrieve its details using puter.apps.get(). It includes cleanup by deleting the created app. ```html ``` -------------------------------- ### Get File Information Source: https://docs.puter.com/FS/stat/index This example demonstrates how to create a file and then retrieve its metadata using puter.fs.stat(). It shows how to access properties like name, path, size, and creation date. ```html ``` -------------------------------- ### Complete Worker Deployment and Testing Example Source: https://docs.puter.com/Workers/create/index This example demonstrates the full workflow: writing worker code to a file, deploying the worker using puter.workers.create(), and then testing its functionality after a short delay for propagation. ```html ``` -------------------------------- ### serve() Source: https://docs.puter.com/Objects/workerinfo Starts a server to listen for incoming peer connections. ```APIDOC ## serve() ### Description Starts a server to listen for incoming peer connections. ### Type Function ``` -------------------------------- ### Example: Flushing Key-Value Store in a Website Source: https://docs.puter.com/KV/flush/index This example demonstrates how to create, list, flush, and re-list key-value pairs using puter.kv functions within a website's HTML and JavaScript. ```html ``` -------------------------------- ### Show Help for a Command Source: https://docs.puter.com/cli/index Displays help information for any Puter CLI command. For example, to get help for 'puter site deploy', use 'puter site deploy --help'. ```sh puter --help ``` -------------------------------- ### HTTP Methods with Puter.net Fetch API Source: https://developer.puter.com/tutorials/cors-free-fetch-api This example shows how to perform GET, POST, PUT, and DELETE requests using `puter.net.fetch()`. The syntax is identical to the native Fetch API. ```javascript
``` -------------------------------- ### Example: Requesting and Using Pictures Write Access Source: https://docs.puter.com/Perms/requestWritePictures/index This example demonstrates how to request write access to the Pictures folder and then write a file to it. It handles both successful permission grants and denials. ```html ``` -------------------------------- ### Flush Key-Value Store Example Source: https://docs.puter.com/KV/flush Demonstrates how to create, list, flush, and re-list key-value pairs using puter.kv functions. This example shows the complete lifecycle of managing data in the key-value store. ```javascript ``` -------------------------------- ### Create, Get, and Delete an App with Puter.js Source: https://docs.puter.com/playground/app-get This snippet shows how to create a new app with a random name and a specified URL, retrieve its details using the `get()` method, and then delete it for cleanup. Ensure the Puter.js SDK is loaded before execution. ```javascript (async () => { // (1) Generate a random app name to make sure it doesn't already exist let appName = puter.randName(); // (2) Create the app await puter.apps.create(appName, "https://example.com"); puter.print(`"${appName}" created
`); // (3) Retrieve the app using get() let app = await puter.apps.get(appName); puter.print(`"${appName}" retrieved using get(): id: ${app.uid}
`); // (4) Delete the app (cleanup) await puter.apps.delete(appName); })(); ``` -------------------------------- ### Hide Spinner Example Source: https://docs.puter.com/UI/hideSpinner This example demonstrates how to show a spinner and then hide it after a 3-second delay using puter.ui.showSpinner() and puter.ui.hideSpinner(). ```html ``` -------------------------------- ### Create, Get, and Delete a Website Source: https://docs.puter.com/playground/hosting-get This snippet shows how to create a new website, retrieve its details using the get() method, and then clean up by deleting it. It's useful for testing website creation and retrieval workflows. ```javascript let subdomain = puter.randName(); const site = await puter.hosting.create(subdomain, '.') document.write(`Website hosted at: ${site.subdomain}.puter.site (This is an empty website with no files)
"); // (2) Retrieve the website using get() const site2 = await puter.hosting.get(site.subdomain); document.write(`Website retrieved: subdomain=${site2.subdomain}.puter.site UID=${site2.uid}
"); // (3) Delete the website (cleanup) await puter.hosting.delete(subdomain); ``` -------------------------------- ### Create an app pointing to example.com Source: https://docs.puter.com/Apps/create/index This example demonstrates how to create a new Puter app with a given name and index URL. It also shows how to retrieve the app's UID and then clean up by deleting the created app. Ensure the Puter JavaScript SDK is included. ```html ``` -------------------------------- ### Define a GET Endpoint with Route Parameters Source: https://docs.puter.com/Workers/router Example of defining a GET endpoint that captures route parameters. The captured segments are available in the params object. ```javascript router.get("/api/posts/:category/:id", async ({ params }) => { const { category, id } = params; return { category, id }; }); ``` -------------------------------- ### Get Current Language Source: https://docs.puter.com/UI/getLanguage/index Retrieves the current language code from the Puter environment. This example demonstrates how to use the function with `.then()` and logs the result. ```javascript puter.ui.getLanguage().then((language) => { console.log('Current language:', language); // Output: "Current language: fr" (if French is selected) }); ``` -------------------------------- ### Create a basic window with options Source: https://docs.puter.com/UI/createWindow/index This example demonstrates how to create a window with custom title, content, dimensions, and behavior settings. Ensure the puter.com/v2/ script is included. ```html ``` -------------------------------- ### Create, List, and Delete Apps Example Source: https://docs.puter.com/prompt Demonstrates the full lifecycle of creating, listing, and then deleting apps. Ensure cleanup to avoid cluttering your app list. ```html ``` -------------------------------- ### Vue.js Component Integration Source: https://docs.puter.com/prompt Import Puter.js and call its methods from your Vue.js component functions. This example uses the Composition API with ` ``` -------------------------------- ### Use Puter.js in Browser (NPM) Source: https://docs.puter.com/getting-started/index Import and use Puter.js in the browser after installing via NPM. This example shows how to use the AI chat functionality. ```javascript import { puter } from "@heyputer/puter.js"; // Example: Use AI to answer a question puter.ai.chat(`Why did the chicken cross the road?`).then(console.log); ``` -------------------------------- ### Create and Host a Simple Website Source: https://docs.puter.com/playground/hosting-create This snippet creates a new directory, writes an 'index.html' file with 'Hello, world!' content, and then hosts this directory under a random subdomain. It's useful for quickly deploying static content. ```html ``` -------------------------------- ### Get the current Puter.js environment Source: https://docs.puter.com/Utils/env/index This example demonstrates how to retrieve and display the current Puter.js environment using the `puter.env` property within an HTML page. ```html ``` -------------------------------- ### Return JSON Response Source: https://developer.puter.com/tutorials/serverless-functions-on-puter A simple example of a GET endpoint that returns a JSON object. The framework automatically serializes the returned object into a JSON response. ```javascript router.get("/api/data", async () => { return { status: "ok", count: 42 }; }); ``` -------------------------------- ### HTML Example for Showing Window Source: https://docs.puter.com/UI/showWindow/index This HTML structure demonstrates how to integrate the `puter.ui.showWindow()` call within a web page. It includes the Puter SDK script and a script block to execute the function. ```html ``` -------------------------------- ### Multi-Turn Image Editing Source: https://docs.puter.com/AI/chat This example illustrates a multi-turn conversation for image editing, starting with image generation and then performing an edit (translation) on the generated image. ```javascript const model = "gemini-3.1-flash-image-preview"; // Step 1: Generate initial image puter.print("Step 1: Generating infographic...
"); const r1 = await puter.ai.chat("Create a simple infographic about photosynthesis", { model, image_config: { image_size: "1K" }, }); const img1 = r1.message.images?.[0]?.image_url?.url; const thoughtSignature1 = r1.message.images?.[0]?.thoughtSignature; if (img1) { const el = document.createElement("img"); el.src = img1; el.style.maxWidth = "512px"; document.body.appendChild(el); } // Step 2: Edit the image in a follow-up turn puter.print("
Step 2: Translating to Spanish...
"); const r2 = await puter.ai.chat([ { role: "user", content: "Create a simple infographic about photosynthesis" }, { role: "assistant", content: [ { type: "text", text: r1.message.content }, { type: "image_url", image_url: { url: img1 }, thoughtSignature: thoughtSignature1 }, ]}, { role: "user", content: "Translate all text to Spanish. Keep everything else the same." }, ], { model, image_config: { aspect_ratio: "16:9", image_size: "2K" }, }); const img2 = r2.message.images?.[0]?.image_url?.url; if (img2) { const el = document.createElement("img"); el.src = img2; el.style.maxWidth = "512px"; document.body.appendChild(el); } puter.print("
Done!"); ``` -------------------------------- ### Get Monthly Usage (HTML with JS) Source: https://docs.puter.com/Auth/getMonthlyUsage/index This example demonstrates how to integrate the getMonthlyUsage function into an HTML page. Ensure the Puter SDK is loaded before calling the function. ```html ``` -------------------------------- ### Create and Delete an App Source: https://docs.puter.com/Apps/delete This example demonstrates how to create a random app and then delete it using `puter.apps.create()` and `puter.apps.delete()`. It also shows how to verify the deletion by attempting to retrieve the app, which should result in an error. ```html ``` -------------------------------- ### Define Serverless Worker Endpoints Source: https://docs.puter.com/supported-platforms/index Example code for creating basic GET and POST endpoints in a Serverless Worker environment. These snippets illustrate handling requests and responses. ```js // Simple GET endpoint router.get("/api/hello", async ({ request }) => { return { message: "Hello, World!" }; }); // POST endpoint with JSON body router.post("/api/user", async ({ request }) => { const body = await request.json(); return { processed: true }; }); ``` -------------------------------- ### puter.hosting.create() Source: https://docs.puter.com/llms.txt Creates and hosts a website from a specified directory on Puter. ```APIDOC ## puter.hosting.create() ### Description Creates and hosts a website from a directory on Puter. ### Method Not specified (SDK method) ### Endpoint Not specified (SDK method) ### Parameters Not specified in source ### Request Example Not specified in source ### Response Not specified in source ``` -------------------------------- ### List Apps with Stats and Icon Size Source: https://docs.puter.com/Apps/list/index This example demonstrates how to create three random apps, list them with specific statistics period and icon size, and then clean up by deleting the created apps. It shows the full lifecycle of app creation, listing, and deletion. ```html ``` -------------------------------- ### Get Max Value Size Source: https://docs.puter.com/KV/MAX_VALUE_SIZE/index This example demonstrates how to retrieve and display the maximum value size supported by the Puter KV store using a simple HTML script. ```html ``` -------------------------------- ### Create a Basic Menubar with File Menu Source: https://docs.puter.com/UI/setMenubar/index This example demonstrates how to create a simple menubar with a 'File' menu. The 'File' menu contains a basic action and a submenu with two more actions. Use this to set up the primary navigation for your application. ```html ``` -------------------------------- ### Full HTML Example for Peer Server Source: https://docs.puter.com/Peer/serve/index A complete HTML page demonstrating how to create a peer server, display the invite code, and handle incoming client connections and messages. ```html ``` -------------------------------- ### List Keys and Values in KV Store Source: https://docs.puter.com/KV/index Demonstrates how to retrieve all keys, all keys with their values, and keys matching a pattern from the KV store. Includes setup and cleanup operations. ```html ``` -------------------------------- ### Launch the Editor App Source: https://docs.puter.com/UI/launchApp/index This example demonstrates how to launch the 'editor' app. Ensure the Puter JS SDK is included in your HTML. ```html ``` -------------------------------- ### Get Worker Information Source: https://docs.puter.com/Workers/get/index This example demonstrates how to fetch and display information for a worker named 'my-api'. It includes basic error handling for when the worker is not found. Ensure the puter.com/v2/ script is included. ```html ``` -------------------------------- ### Peer-to-Peer Chat with Puter.js Source: https://docs.puter.com/playground/peer-basic This example allows you to create a simple peer-to-peer chat application. Open the page in two tabs, start a server in one, and connect from the other to exchange messages. It requires the Puter.js v2 library. ```html

Peer Chat

Open this page in two tabs. Start a server in one tab, then connect from the other.


  


```

--------------------------------

### Request Desktop Write Access and Write File

Source: https://docs.puter.com/Perms/requestWriteDesktop

This example demonstrates how to request write access to the Desktop folder and then write a file to it. It handles both granting and denying of permissions. Ensure the Puter SDK v2 is included.

```html


    
    
    


```

--------------------------------

### Get Parent App Connection

Source: https://docs.puter.com/UI/parentApp

This example demonstrates how to use puter.ui.parentApp() to check if the current app has a parent and interact with it. It alerts the user whether the app was launched directly or by another app, and if a parent exists, it sends a message to it.

```html


    
    


```

--------------------------------

### Request Pictures Read Access

Source: https://docs.puter.com/Perms/requestReadPictures

This example demonstrates how to use `puter.perms.requestReadPictures()` to get access to the Pictures folder. It includes a button to trigger the request and logs the result to the console. Ensure the Puter SDK is loaded before executing this script.

```html


    
    
    


```

--------------------------------

### Publish Static Website

Source: https://docs.puter.com/

Creates a new directory, writes an 'index.html' file with 'Hello, world!' content, and hosts the directory under a random subdomain. The URL of the hosted website is then printed.

```html


    
    


```

--------------------------------

### Install @heyputer/worker-types

Source: https://docs.puter.com/Workers/types/index

Install the package as a development dependency using npm.

```sh
npm install --save-dev @heyputer/worker-types
```

--------------------------------

### Deploy Website with Puter CLI

Source: https://docs.puter.com/deployments/index

Deploy a website's directory to a *.puter.site subdomain using the Puter CLI. Both directory and subdomain arguments are optional, and the CLI will prompt for them if not provided.

```bash
puter site deploy [dir] [subdomain]
```

--------------------------------

### Install Puter.js via NPM

Source: https://docs.puter.com/getting-started/index

Install the Puter.js library using NPM for use in your project.

```plaintext
npm install @heyputer/puter.js
```

--------------------------------

### Create a TLS Socket and Send HTTP Request

Source: https://docs.puter.com/playground/net-tls

Establishes a TLS connection to example.com on port 443, sends an HTTP GET request, and prints the received data or any errors.

```html


 
 


```

--------------------------------

### Get Parent App Connection

Source: https://docs.puter.com/UI/parentApp/index

Use this function to get a connection to the parent app. Returns null if there is no parent.

```javascript
const parent = puter.ui.parentApp();
if (!parent) {
    alert('This app was launched directly');
} else {
    alert('This app was launched by another app');
    parent.postMessage("Hello, parent!");
}
```

--------------------------------

### Basic Directory Picker Usage

Source: https://docs.puter.com/UI/showDirectoryPicker/index

This example demonstrates how to use `puter.ui.showDirectoryPicker()` to open a directory picker and display the selected directory's name and content. It requires including the Puter JS SDK and has a button to trigger the picker.

```html


    

    

    

``` -------------------------------- ### Install Puter CLI Source: https://docs.puter.com/Workers/index Install the Puter CLI globally using npm. This tool is used for deploying workers from the terminal. ```bash npm install -g @heyputer/cli ``` -------------------------------- ### puter.ui.createWindow() Source: https://docs.puter.com/llms.txt Creates and displays a window. ```APIDOC ## puter.ui.createWindow() ### Description Creates and displays a window. ### Method (Not specified, likely a function call) ### Endpoint (Not applicable, SDK function) ### Parameters (No parameters specified) ### Response (No response details specified) ``` -------------------------------- ### Simple GET Endpoint Source: https://docs.puter.com/Workers/index Defines a basic GET route that returns a JSON message. Use for simple API endpoints. ```javascript router.get("/api/hello", async ({ request }) => { return { message: "Hello, World!" }; }); ``` -------------------------------- ### Puter KV List Syntax Examples Source: https://docs.puter.com/prompt Demonstrates various ways to call the `puter.kv.list()` function with different parameters and options. ```javascript puter.kv.list() ``` ```javascript puter.kv.list(pattern) ``` ```javascript puter.kv.list(returnValues = false) ``` ```javascript puter.kv.list(pattern, returnValues = false) ``` ```javascript puter.kv.list(options) ``` -------------------------------- ### GET /*tag Source: https://docs.puter.com/Workers/router A wildcard route handler for any GET requests not explicitly matched by other routes, typically used for 404 Not Found responses. ```APIDOC ## GET /*tag ### Description A wildcard route handler for any GET requests not explicitly matched by other routes, typically used for 404 Not Found responses. ### Method GET ### Endpoint /*tag ### Parameters #### Path Parameters - **tag** (string) - Required - The unmatched path segment. ### Response #### Success Response (404) - **error** (string) - "Not found" - **path** (string) - The requested path that was not found. - **availableEndpoints** (array) - A list of available endpoints. ### Response Example { "error": "Not found", "path": "/some/nonexistent/path", "availableEndpoints": [ "/health", "/api/users", "/api/files/upload" ] } ``` -------------------------------- ### Basic Worker Deletion Example Source: https://docs.puter.com/prompt Demonstrates how to create, delete, and then attempt to retrieve a worker to confirm deletion. This example is intended for web environments. ```html ```