DeveloperBreeze

Fetching Chuck Norris Jokes from API in JavaScript

const apiUrl = 'https://api.chucknorris.io/jokes/random';
fetch(apiUrl)
    .then(response => response.json())
    .then(data => console.log('Chuck Norris Joke:', data.value))
    .catch(error => console.error('Error:', error));

Continue Reading

Discover more amazing content handpicked just for you

Code
javascript

Dynamic and Responsive DataTable with Server-Side Processing and Custom Styling

  • initComplete: Adds custom classes to dropdowns and inputs in the DataTables UI for consistent styling.
  • drawCallback: Applies custom classes to various table elements (e.g., rows, headers, cells) after each table draw to enhance the appearance.

Oct 24, 2024
Read More
Tutorial
php

Handling HTTP Requests and Raw Responses in Laravel

In Laravel, making HTTP requests is made easy with the Http facade, which provides a simple and fluent interface to interact with external APIs. In this tutorial, we will explore how to make POST requests, handle various types of responses, and process raw response bodies in a Laravel application.

Ensure you have a Laravel project set up. You can create a new Laravel project by running:

Oct 24, 2024
Read More
Article
javascript

20 Useful Node.js tips to improve your Node.js development skills:

No preview available for this content.

Oct 24, 2024
Read More
Tutorial
javascript

AJAX with JavaScript: A Practical Guide

In many real-world applications, you'll need to send data to the server using POST requests. Here's how to send form data using the Fetch API.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POST Request with Fetch</title>
</head>
<body>
    <form id="postDataForm">
        <input type="text" id="title" placeholder="Enter title" required>
        <input type="text" id="body" placeholder="Enter body" required>
        <button type="submit">Submit</button>
    </form>
    <div id="postDataOutput"></div>

    <script>
        document.getElementById('postDataForm').addEventListener('submit', function(e) {
            e.preventDefault();

            const title = document.getElementById('title').value;
            const body = document.getElementById('body').value;

            fetch('https://jsonplaceholder.typicode.com/posts', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    title: title,
                    body: body
                })
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById('postDataOutput').innerHTML = `
                    <h3>Data Submitted:</h3>
                    <p>Title: ${data.title}</p>
                    <p>Body: ${data.body}</p>
                `;
            })
            .catch(error => console.error('Error:', error));
        });
    </script>
</body>
</html>

Sep 18, 2024
Read More
Tutorial
javascript

Advanced JavaScript Tutorial for Experienced Developers

Here, the closure captures the loop variable i, and since var has function scope, all the setTimeout callbacks reference the same i, which is 3 after the loop ends.

To fix this, you can use let instead of var, which has block scope:

Sep 02, 2024
Read More
Tutorial
javascript

Getting Started with Axios in JavaScript

axios.get('https://jsonplaceholder.typicode.com/posts/1', {
    headers: {
      'Authorization': 'Bearer YOUR_TOKEN_HERE'
    }
  })
  .then(response => {
    console.log('Post data:', response.data);
  })
  .catch(error => {
    console.error('Error fetching data:', error);
  });

Axios allows you to make multiple requests simultaneously using axios.all() and axios.spread().

Sep 02, 2024
Read More
Cheatsheet
solidity

Solidity Cheatsheet

interface MyInterface {
    function setData(uint _data) external;
    function getData() external view returns (uint);
}

contract MyContract is MyInterface {
    uint private data;

    function setData(uint _data) external override {
        data = _data;
    }

    function getData() external view override returns (uint) {
        return data;
    }
}

Libraries are similar to contracts but are meant to hold reusable code. They cannot hold state.

Aug 22, 2024
Read More
Tutorial
bash

Creating and Managing Bash Scripts for Automation

   chmod +x my_first_script.sh

Execute the script by typing:

Aug 19, 2024
Read More
Code
javascript

React Custom Hook for API Requests

No preview available for this content.

Aug 12, 2024
Read More
Code
python

Python Logging Snippet

  • Error Handling: The code demonstrates how to log exceptions with stack traces using exc_info=True or the exception() method.

  • Add Logging to Your Application: Use this snippet to quickly integrate logging into any Python application.

Aug 08, 2024
Read More
Code
javascript

Fetching Weather Information from OpenWeatherMap API

No preview available for this content.

Jan 26, 2024
Read More
Code
php

PHP File Upload

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Promise-based Execution of Python Code with jsPython

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript python

Execute Python Code Using Skulpt

  • Executing the Python Code:
  • Sk.misceval.asyncToPromise runs the Python code asynchronously.
  • It calls Sk.importMainWithBody to execute the code as the main module.
  • Success Callback: If execution is successful, it logs a success message to the console.
  • Error Callback: If an error occurs during execution, it catches the error and logs an error message.
  • Purpose of the Code:
  • This setup allows developers to run Python scripts directly in the browser without needing a server-side interpreter.
  • It's useful for educational tools, interactive tutorials, or any application that benefits from executing Python code on the client side.

Jan 26, 2024
Read More
Code
javascript

POST Request with Fetch API and JSON Data

No preview available for this content.

Jan 26, 2024
Read More
Code
python

Bybit Futures API Integration Using ccxt Library with Error Handling

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!