Skip to content

Commit 58ded23

Browse files
committed
Update consolidated snippets
1 parent a90466b commit 58ded23

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

public/consolidated/javascript.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,58 @@
419419
"contributors": [],
420420
"code": "const times = (func, n) => {\n Array.from(Array(n)).forEach(() => {\n func();\n });\n};\n\n// Usage:\nconst randomFunction = () => console.log('Function called!');\ntimes(randomFunction, 3); // Logs 'Function called!' three times\n"
421421
},
422+
{
423+
"title": "DELETE request",
424+
"description": "Simple request a DELETE api endpoint with a body",
425+
"author": "kruimol",
426+
"tags": [
427+
"javascript",
428+
"function",
429+
"fetch",
430+
"delete"
431+
],
432+
"contributors": [],
433+
"code": "// then\nfetch(\"/api/delete\" /* api endpoint */, {\n method: \"DELETE\",\n})\n .then((response) => response.text())\n .then((response) => {\n console.log(response);\n })\n .catch((error) => console.error(\"Error:\", error));\n"
434+
},
435+
{
436+
"title": "GET request",
437+
"description": "Simple request a GET api endpoint",
438+
"author": "kruimol",
439+
"tags": [
440+
"javascript",
441+
"function",
442+
"fetch",
443+
"get"
444+
],
445+
"contributors": [],
446+
"code": "// then\nfetch(\"/api/get\" /* api endpoint */)\n .then((response) => {\n console.log(response);\n })\n .catch((error) => console.error(\"Error:\", error));\n"
447+
},
448+
{
449+
"title": "POST request",
450+
"description": "Simple request a POST api endpoint with a body",
451+
"author": "kruimol",
452+
"tags": [
453+
"javascript",
454+
"function",
455+
"fetch",
456+
"post"
457+
],
458+
"contributors": [],
459+
"code": "// then\nfetch(\"/api/post\" /* api endpoint */, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ a: 1, b: \"Textual content\" })\n})\n .then((response) => response.json())\n .then((response) => {\n console.log(response);\n })\n .catch((error) => console.error(\"Error:\", error));\n"
460+
},
461+
{
462+
"title": "PUT request",
463+
"description": "Simple request a PUT api endpoint with a body",
464+
"author": "kruimol",
465+
"tags": [
466+
"javascript",
467+
"function",
468+
"fetch",
469+
"put"
470+
],
471+
"contributors": [],
472+
"code": "// then\nfetch(\"/api/PUT\" /* api endpoint */, {\n method: \"PUT\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ a: 1, b: \"Textual content\" })\n})\n .then((response) => response.json())\n .then((response) => {\n console.log(response);\n })\n .catch((error) => console.error(\"Error:\", error));\n"
473+
},
422474
{
423475
"title": "Sleep Function",
424476
"description": "Waits for a specified amount of milliseconds before resolving.",

0 commit comments

Comments
 (0)