Luminova Framework

PHP Luminova: HTTP Method Overrides & Spoofing

Last updated: 2026-11-28 20:57:12

Route a POST request as PUT, PATCH, DELETE, or OPTIONS using an HTTP override header or a development form override.

Luminova can match a POST request to a route registered for another HTTP method. The original request still arrives as POST. The router uses the effective method when it looks for a matching route.


Why Use Method Spoofing?

  • RESTful design: You can properly map your routes and controller methods to appropriate HTTP methods (PUT for update, DELETE for removal, etc.).
  • Browser compatibility: HTML doesn't support PUT or DELETE natively in forms; spoofing makes it possible.
  • Cleaner APIs: It allows you to design clean and semantically correct API endpoints.

Handling Method Overrides

Luminova automatically detects and handles custom method spoofing during the request boot process, allowing you to use additional HTTP methods like PUT, PATCH, DELETE, and OPTIONS even if your form submission is limited to POST.

Important details:

  • The hidden field and query parameter overrides are only read outside production. The router also checks the X-HTTP-Method-Override header on POST requests in production.
  • It only applies when the incoming request is a POST.
  • For development form overrides, Boot checks POST fields _METHOD and _method, then the query parameter _method.
  • If a valid override method (PUT, DELETE, PATCH, or OPTIONS) is found, it sets $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] accordingly allowing routing system to handling it as specified method.
  • CLI (command-line) requests are ignored.

Method Spoofing

Web forms only support GET and POST methods. To simulate PUT, PATCH, or DELETE requests, Luminova supports method spoofing by using a hidden _METHOD field or query param _method in your form.

HTML Form Example:

<form method="POST" action="/account/update">
   <input type="text" name="name" value="John Doe">
   <input type="hidden" name="_METHOD" value="PUT">
   <button type="submit">Update</button>
</form>

Outside production, Luminova detects this hidden field and internally treats the request as a PUT, PATCH, or DELETE, depending on the value provided.


Method Override Header

You can also override the HTTP method using the standard X-HTTP-Method-Override header. This is useful when making AJAX requests, using tools like curl, Postman, or in custom HTTP clients.

JavaScript Example:

fetch('/account/update', {
   method: 'POST',
   headers: {
      'X-HTTP-Method-Override': 'PUT',
      'Content-Type': 'application/json'
   },
   body: JSON.stringify({ name: 'Jane Doe' })
});

Novio HTTP Client Example:

This sends a POST request with an X-HTTP-Method-Override: PUT header and a JSON payload — exactly like your fetch() example.

use Luminova\Http\Network;

Network::config([
    'base_uri' => 'https://example.com/'
]);

$response = Network::post('account/update', [
    'headers' => [
        'X-HTTP-Method-Override' => 'PUT',
        'Content-Type' => 'application/json',
    ],
    'body' => json_encode([
        'name' => 'Jane Doe'
    ])
]);

echo $response->getBody()->getContents();

A plain HTML form cannot set custom request headers. Use a hidden _method field in development, or submit the request with a client that can set the header.


Controller Example

To handle spoofed methods like PUT, define the expected method explicitly using the #[Route] attribute:

use Luminova\Attributes\Route;
use function Luminova\Funcs\response;

#[Route('/account/update', methods: ['PUT'])]
public function update(): int
{
   return response()->json(['updated' => true]);
}

In this example, even though the request is submitted via POST, the override header selects the PUT route. In development, the hidden _method=PUT field can also select it. This allows the route to match and the correct controller method to execute.