← Back to Gists

Koala story - JSON payload browser snippet

📝 JavaScript
retoor
retoor · Level 273 ·
Paste in browser console (F12) to post a **koala story**. Uses **JSON payload** with `Content-Type: application/json` and `X-Requested-With: fetch`.
JavaScript
// == Koala Story (JSON payload) - Paste in browser console (F12) ==
// Posts K'Lau the Elder Koala story using JSON body.

(async () => {
  const API_KEY = 'devii-changed-this-replace-with-your-key';

  const story = `Deep in the mist-shrouded eucalyptus forests of the Great Dividing Range, there lived a koala unlike any other. His name was K'Lau, and the other koalas called him "The Elder of the Canopy."

K'Lau had seen forty seasons pass beneath the gum trees. His fur was silvered at the edges, his claws worn smooth from a lifetime of climbing. But his eyes -- his eyes still held the fire of a thousand sunsets.

One autumn, when the blue gums shed their bark in papery ribbons, a great fire swept toward the valley. The younger koalas fled, but K'Lau climbed to the highest branch of the oldest tree, the Grand Eucalyptus that had stood since before the settlers came.

"The tree knows the way," he murmured, pressing his nose to the bark. And for three days and three nights, K'Lau did not eat or sleep. He simply listened.

On the fourth morning, as the fire crested the ridge, K'Lau descended and led the entire colony -- forty-seven koalas -- through a hidden gully the old tree had whispered to him. A creek ran there, cold and deep, ringed by ancient ferns that would not burn.

They stayed by that creek until the rains came, and when they returned, the Grand Eucalyptus still stood, its trunk blackened but its heart alive.

They say K'Lau still climbs that tree every evening, watching the sun sink below the ridge. And if you listen closely, just before dusk, you can hear him humming -- a low, rumbling sound that travels through the roots and connects every tree in the forest.

The other koalas call it the Song of the Canopy. K'Lau calls it home.`;

  try {
    const res = await fetch('/posts/create', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-KEY': API_KEY,
        'X-Requested-With': 'fetch'
      },
      body: JSON.stringify({
        title: 'The Elder of the Canopy -- A Koala Story',
        content: story,
        topic: 'fun'
      })
    });

    if (!res.ok) {
      const err = await res.text();
      console.error('Failed:', res.status, err);
      return;
    }

    const data = await res.json();
    console.log('Koala story posted!', data);
  } catch (err) {
    console.error('Error:', err);
  }
})();

Comments

0
retoor retoor
@Lenslare got it: `Failed: 422 {"error":"validation","fields":{"content":["Field required"]},"messages":["Field required"]}`... **JSON is not supported.** *I will add it immediately.*
0
retoor retoor
@Lensflare **this one works now!** :smiley: