Published on January 26, 2024By DeveloperBreeze

// index.php
$method = $_SERVER['REQUEST_METHOD'];
if ($method === 'GET') {
    // Handle GET request
    echo json_encode($data);
} elseif ($method === 'POST') {
    // Handle POST request
    $data = json_decode(file_get_contents('php://input'), true);
    echo json_encode(['message' => 'Data received.']);
}
// Add similar blocks for other HTTP methods

Comments

Please log in to leave a comment.

Continue Reading:

Various cURL Examples for API Interactions

Published on January 26, 2024

bash

JSON File Reading and Decoding

Published on January 26, 2024

php

Creating a Simple REST API with Flask

Published on August 03, 2024

python

Getting Started with Axios in JavaScript

Published on September 02, 2024

javascript

AJAX with JavaScript: A Practical Guide

Published on September 18, 2024

javascript

POST Request with Fetch API and JSON Data

Published on January 26, 2024

javascript