# Workers Exec - Authenticated Requests

Test authenticated requests to worker endpoints using `puter.workers.exec()`.

### Setup

First, create a test worker with the following code:

// Test worker with authentication router.get('/api/hello', async (event) => { const authHeader = event.request.headers.get('puter-auth'); return { message: 'Hello from authenticated worker!', authenticated: !!authHeader, timestamp: new Date().toISOString() }; }); router.get('/api/user-profile', async (event) => { const authHeader = event.request.headers.get('puter-auth'); if (!authHeader) { return new Response(JSON.stringify({ error: 'Authentication required' }), { status: 401, headers: { 'Content-Type': 'application/json' } }); } return { user: 'authenticated-user', profile: { name: 'John Doe', email: 'john@example.com' }, timestamp: new Date().toISOString() }; }); router.post('/api/data', async (event) => { const authHeader = event.request.headers.get('puter-auth'); if (!authHeader) { return new Response(JSON.stringify({ error: 'Authentication required' }), { status: 401, headers: { 'Content-Type': 'application/json' } }); } const body = await event.request.json(); return { received: body, saved: true, timestamp: new Date().toISOString() }; }); router.put('/api/settings', async (event) => { const authHeader = event.request.headers.get('puter-auth'); if (!authHeader) { return new Response(JSON.stringify({ error: 'Authentication required' }), { status: 401, headers: { 'Content-Type': 'application/json' } }); } const body = await event.request.json(); return { updated: body, success: true, timestamp: new Date().toISOString() }; }); router.delete('/api/resource/:id', async (event) => { const authHeader = event.request.headers.get('puter-auth'); if (!authHeader) { return new Response(JSON.stringify({ error: 'Authentication required' }), { status: 401, headers: { 'Content-Type': 'application/json' } }); } const id = event.params.id; return { deleted: id, success: true, timestamp: new Date().toISOString() }; }); router.get('/api/health', async (event) => { return { status: 'healthy', uptime: Date.now(), timestamp: new Date().toISOString() }; }); router.options('/*page', ({request}) => { return new Response(null, { status: 204, headers: { 'Access-Control-Allow-Origin': request.headers.get('origin'), 'Access-Control-Allow-Headers': '*', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Methods': '*' } }); });
Worker Name:

### Request Builder

Endpoint:
Request Body (JSON):
Headers (optional):

### Quick Tests

### Batch Operations