Reputation: 43
I have a problem with Restler: I'm creating my own API to access my data from differente website. When I try to send a POST request to my API, it says:
{
error: {
code: 405
message: "Method Not Allowed"
}
debug: {
source: "Routes.php:422 at route stage"
stages: {
success: [1]
0: "get"
failure: [3]
0: "route"
1: "negotiate"
2: "message"
}
}
}
My index.php code is:
<?php
require_once 'vendor/restler.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('v1'); // repeat for more
$r->handle(); //serve the response
I have already tried to put:
header('Access-Control-Allow-Methods: *');
but nothing. Can someone help, please?
Upvotes: 1
Views: 736
Reputation: 1098
In order Restler to accept POST requests, post function has to be implemented your v1 class.
A typical example can be:
function post($request_data = NULL){
$result = new stdClass();
$result->sometitle = 'OK';
return $result;
}
where $request_data
is the Array with your passed POST parameters.
This function will be accessed only on POST method and it will return:
{
"sometitle ": "OK"
}
Upvotes: 4