|
419 | 419 | "contributors": [],
|
420 | 420 | "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"
|
421 | 421 | },
|
| 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 | + }, |
422 | 474 | {
|
423 | 475 | "title": "Sleep Function",
|
424 | 476 | "description": "Waits for a specified amount of milliseconds before resolving.",
|
|
0 commit comments