-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DELETE body request ? #190
Comments
Hi Hugo, You should be able to send a request body for any method type, and your use-case seems to be a totally valid one. Ensure that your defined resource is configured to allow it with the correct content type (@accepts). If you're still having problems, stick some more info into of your specific case into this issue or create a test case that fails in a pull request. Paul. |
Hey Paul ! I've made it but what is strange is I had to remove @accepts line !! Quite weird ! For informational purpose, here is how I get PUT, GET, POST & DELETE requests works : /**
* @uri /website
*/
class WebsiteApi extends Tonic\Resource
{
/**
* @method GET
* @json
* @provides application/json
* @return Tonic\Response
*/
function get()
{
error_log('WebsiteApi GET : ' . json_encode($this->request->data));
return new Tonic\Response(Tonic\Response::OK, array('status' => 'success'));
}
/**
* @method POST
* @json
* @provides application/json
* @return Tonic\Response
*/
function create()
{
error_log('WebsiteApi POST : ' . json_encode($this->request->data));
return new Tonic\Response(Tonic\Response::OK, array('status' => 'success'));
}
/**
* @method PUT
* @json
* @provides application/json
* @return Tonic\Response
*/
function update() {
error_log('WebsiteApi PUT : ' . json_encode($this->request->data));
return new Tonic\Response(Tonic\Response::OK, array('status' => 'success'));
}
/**
* @method DELETE
* @json
* @provides application/json
* @return Tonic\Response
*/
function remove()
{
error_log('WebsiteApi DELETE : ' . json_encode($this->request->data));
return new Tonic\Response(Tonic\Response::OK, array('status' => 'success'));
}
/**
* Process all request's data as json : encode / decode
*/
function json()
{
$this->before(function ($request)
{
if ($request->contentType == "application/json")
{
$request->data = json_decode($request->data);
}
});
$this->after(function ($response)
{
$response->contentType = "application/json";
$response->body = json_encode($response->body);
});
}
} By the way, I have to tell you In your readme, you provide an example with a list() function : that throws me an error (at least with my version of PHP) : you can't use reserved words ... |
Hi and thanks for your API !
I'm wondering why I can't send DELETE entity body params but only URL params. When trying to do so I get a 415 (Unsupported Media Type).
Googling around makes me think it should be possible, could you please highlight me on the subject ?
The reason for this is when I want to delete a user I send its id but I also want to send a delete reason (I could add a second param but as it is text, I feel it would be a cleaner solution to send it through body ...)
Hugo
The text was updated successfully, but these errors were encountered: