// 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 methodsSimple Server-Side Handling of HTTP Methods
Related Posts
More content you might like
AJAX with JavaScript: A Practical Guide
Fetch and display search results in real-time as users type in the search box.
Fetch and update filtered data dynamically without reloading the entire page.
Getting Started with Axios in JavaScript
Let's start by making a simple GET request to a public API using Axios.
Example:
REST API Cheatsheet: Comprehensive Guide with Examples
This REST API cheatsheet provides a comprehensive overview of the most commonly used REST API concepts, complete with examples to help you quickly find the information you need. Whether you're building or consuming APIs, this guide serves as a quick reference to help you work more efficiently with REST APIs.
Building a RESTful API with Go and Gorilla Mux
curl -X GET http://localhost:8000/books/b1 curl -X PUT http://localhost:8000/books/b1 -H "Content-Type: application/json" -d '{"title":"Advanced Go","author":"Jane Smith","year":"2024"}'Discussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!