🔌 Documentação da API

⚠️ Nota de Segurança: Seu token de API é gerado e exibido exclusivamente dentro da interface do editor. Nunca exponha seu token em código do lado do cliente (client-side) ou o compartilhe. A rotação do token invalidará o anterior imediatamente.

POST/api/v1

Endpoint CRUD unificado para gerenciamento de pens. Todas as operações requerem o parâmetro token.

Autenticação

Todas as requisições para /api/v1 exigem um token de API seguro. Gere o seu token através da janela modal de Configurações (menu do usuário no cabeçalho).

🔹 action: manage_pens

Operações CRUD de Pen

ParâmetroTipoObrigatórioDescrição
actionstringSimmanage_pens
tokenstringSimSeu token de API (64 caracteres)
operationstringNãocreate, read, update, delete (padrão: create)
slugstringPara read/update/deleteIdentificador único (slug) do Pen
titlestringNãoTítulo do Pen (padrão: "Untitled")
htmlstringNãoConteúdo HTML
cssstringNãoConteúdo CSS
jsstringNãoConteúdo JavaScript
templatestringNãoTemplate HTML customizado com marcadores (placeholders)

Exemplos por Operação:

🔹 operation: create

Cria um novo pen com um slug gerado automaticamente.

// Payload de envio { "action": "manage_pens" "token": "[SEU_TOKEN]", "operation": "create", "title": "My Pen", "html": "<div>Hello</div>", "css": "body { color: blue; }", "js": "console.log('hi');", "template": null }
curl -X POST "https://serverless.crom.me/api/v1" \ -H "Content-Type: application/json" \ -d '{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "create", "title": "My Pen", "html": "<div>Hello</div>", "css": "body { color: blue; }", "js": "console.log('\''hi'\'');", "template": null }'
<?php $url = "https://serverless.crom.me/api/v1"; $data = [ "token" => "[SEU_TOKEN]", "action" => "manage_pens", "operation" => "create", "title" => "My Pen", "html" => "<div>Hello</div>", "css" => "body { color: blue; }", "js" => "console.log('hi');", "template" => null ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
const url = 'https://serverless.crom.me/api/v1'; const data = { action: 'manage_pens', token: '[SEU_TOKEN]', operation: 'create', title: 'My Pen', html: '<div>Hello</div>', css: 'body { color: blue; }', js: "console.log('hi');", template: null }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error(err));
import requests url = "https://serverless.crom.me/api/v1" payload = { "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "create", "title": "My Pen", "html": "<div>Hello</div>", "css": "body { color: blue; }", "js": "console.log('hi');", "template": None } response = requests.post(url, json=payload) print(response.json())
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://serverless.crom.me/api/v1" payload := map[string]interface{}{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "create", "title": "My Pen", "html": "<div>Hello</div>", "css": "body { color: blue; }", "js": "console.log('hi');", "template": nil, } jsonPayload, _ := json.Marshal(payload) resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload)) defer resp.Body.Close() fmt.Println("Status da Resposta:", resp.Status) }

Resposta de sucesso: {"success": true, "id": 123, "slug": "a1b2c3d4", "operation": "create"}

🔹 operation: read

Retorna os detalhes completos de um Pen específico através do slug.

{ "action": "manage_pens" "token": "[SEU_TOKEN]", "operation": "read", "slug": "a1b2c3d4" }
curl -X POST "https://serverless.crom.me/api/v1" \ -H "Content-Type: application/json" \ -d '{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "read", "slug": "a1b2c3d4" }'
<?php $url = "https://serverless.crom.me/api/v1"; $data = [ "token" => "[SEU_TOKEN]", "action" => "manage_pens", "operation" => "read", "slug" => "a1b2c3d4" ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
const url = 'https://serverless.crom.me/api/v1'; const data = { action: 'manage_pens', token: '[SEU_TOKEN]', operation: 'read', slug: 'a1b2c3d4' }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error(err));
import requests url = "https://serverless.crom.me/api/v1" payload = { "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "read", "slug": "a1b2c3d4" } response = requests.post(url, json=payload) print(response.json())
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://serverless.crom.me/api/v1" payload := map[string]interface{}{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "read", "slug": "a1b2c3d4", } jsonPayload, _ := json.Marshal(payload) resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload)) defer resp.Body.Close() fmt.Println("Status da Resposta:", resp.Status) }

Resposta: {"id": 123, "slug": "a1b2c3d4", "title": "My Pen", "html": "...", "css": "...", "js": "...", "template": null, "created_at": "...", "updated_at": "..."}

🔹 operation: update

Atualiza as informações de um Pen existente identificado pelo slug.

{ "action": "manage_pens" "token": "[SEU_TOKEN]", "operation": "update", "slug": "a1b2c3d4", "title": "Updated Title", "html": "<div>Updated</div>", "css": "body { color: red; }", "js": "console.log('updated');" }
curl -X POST "https://serverless.crom.me/api/v1" \ -H "Content-Type: application/json" \ -d '{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "update", "slug": "a1b2c3d4", "title": "Updated Title", "html": "<div>Updated</div>", "css": "body { color: red; }", "js": "console.log('\''updated'\'');" }'
<?php $url = "https://serverless.crom.me/api/v1"; $data = [ "token" => "[SEU_TOKEN]", "action" => "manage_pens", "operation" => "update", "slug" => "a1b2c3d4", "title" => "Updated Title", "html" => "<div>Updated</div>", "css" => "body { color: red; }", "js" => "console.log('updated');" ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
const url = 'https://serverless.crom.me/api/v1'; const data = { action: 'manage_pens', token: '[SEU_TOKEN]', operation: 'update', slug: 'a1b2c3d4', title: 'Updated Title', html: '<div>Updated</div>', css: 'body { color: red; }', js: "console.log('updated');" }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error(err));
import requests url = "https://serverless.crom.me/api/v1" payload = { "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "update", "slug": "a1b2c3d4", "title": "Updated Title", "html": "<div>Updated</div>", "css": "body { color: red; }", "js": "console.log('updated');" } response = requests.post(url, json=payload) print(response.json())
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://serverless.crom.me/api/v1" payload := map[string]interface{}{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "update", "slug": "a1b2c3d4", "title": "Updated Title", "html": "<div>Updated</div>", "css": "body { color: red; }", "js": "console.log('updated');", } jsonPayload, _ := json.Marshal(payload) resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload)) defer resp.Body.Close() fmt.Println("Status da Resposta:", resp.Status) }

Resposta: {"success": true, "slug": "a1b2c3d4", "operation": "update"}

🔹 operation: delete

Remove permanentemente um Pen do sistema.

{ "action": "manage_pens" "token": "[SEU_TOKEN]", "operation": "delete", "slug": "a1b2c3d4" }
curl -X POST "https://serverless.crom.me/api/v1" \ -H "Content-Type: application/json" \ -d '{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "delete", "slug": "a1b2c3d4" }'
<?php $url = "https://serverless.crom.me/api/v1"; $data = [ "token" => "[SEU_TOKEN]", "action" => "manage_pens", "operation" => "delete", "slug" => "a1b2c3d4" ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
const url = 'https://serverless.crom.me/api/v1'; const data = { action: 'manage_pens', token: '[SEU_TOKEN]', operation: 'delete', slug: 'a1b2c3d4' }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error(err));
import requests url = "https://serverless.crom.me/api/v1" payload = { "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "delete", "slug": "a1b2c3d4" } response = requests.post(url, json=payload) print(response.json())
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://serverless.crom.me/api/v1" payload := map[string]interface{}{ "action": "manage_pens", "token": "[SEU_TOKEN]", "operation": "delete", "slug": "a1b2c3d4", } jsonPayload, _ := json.Marshal(payload) resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload)) defer resp.Body.Close() fmt.Println("Status da Resposta:", resp.Status) }

Resposta: {"success": true, "slug": "a1b2c3d4", "deleted": 1, "operation": "delete"}

🔹 action: list_pens

Retorna todos os pens do usuário autenticado com slug, título, datas e estatísticas.

Requisição:

{ "action": "list_pens" "token": "[SEU_TOKEN]", }
curl -X POST "https://serverless.crom.me/api/v1" \ -H "Content-Type: application/json" \ -d '{ "action": "list_pens" "token": "[SEU_TOKEN]", }'
<?php $url = "https://serverless.crom.me/api/v1"; $data = ["token" => "[SEU_TOKEN]", "action" => "list_pens"]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?>
const url = 'https://serverless.crom.me/api/v1'; const data = { action: 'list_pens', token: '[SEU_TOKEN]' }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error(err));
import requests url = "https://serverless.crom.me/api/v1" payload = {"action": "list_pens", "token": "[SEU_TOKEN]"} response = requests.post(url, json=payload) print(response.json())
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://serverless.crom.me/api/v1" payload := map[string]interface{}{ "action": "list_pens", "token": "[SEU_TOKEN]", } jsonPayload, _ := json.Marshal(payload) resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload)) defer resp.Body.Close() fmt.Println("Status da Resposta:", resp.Status) }

Resposta: [{"slug": "abc123", "title": "My Pen", "creation_date": "2024-01-15 10:30:00", "last_modified_date": "2024-01-15 14:45:00", "stars": 5, "forks": 2}, ...]

Marcadores de Template (Placeholders)

Ao utilizar templates customizados, os seguintes marcadores estão disponíveis para substituição dinâmica:

MarcadorDescrição
{{title}}Título do Pen (com escape HTML protetivo)
{{html}}Conteúdo HTML bruto
{{css}}Conteúdo CSS bruto
{{js}}Conteúdo JavaScript bruto
{{style}}Estrutura completa com a tag de envolvimento <style>
{{script}}Estrutura completa com a tag de envolvimento <script>