2

In my App I cant use Frameworks like Mojo or Dancer or so on.

I have to check for the request method by

CGI->new()->request_method

And I know I can get the Parameters from POST or PUT by

CGI->new()->param('POSTDATA') # OR 'PUTDATA'

I have to this because the data which I get is JSON with header=application/json

But what can I do when I have da DELETE-Request?

CGI->new()->request_method eq 'DELETE'

works. But what about the params?

  • 4
    Are you in general using the CGI module? Creating a new instance for every method you want to use seems... wasteful. – simbabque Feb 01 '17 at 10:52
  • 1
    Related: [Is an entity body allowed for an HTTP DELETE request?](http://stackoverflow.com/q/299628/1331451) – simbabque Feb 01 '17 at 10:53
  • Yes I'm using it general. I'm not creating new instance for every method, this is just for example here. –  Feb 01 '17 at 10:58
  • 1
    I don't think CGI.pm can do that. [According to this piece of code](https://metacpan.org/source/LEEJO/CGI-4.35/lib/CGI.pm#L641) it looks like only PUT and POST are supported. It also seems to be hard to monkeypatch that in. – simbabque Feb 01 '17 at 10:59
  • 1
    The point is that in a DELETE you would typically not have a body, because the URI is already enough to identify what you want to DELETE. At least if you want RESTful. But in general that also makes sense. What kind of data do you have in the body? – simbabque Feb 01 '17 at 11:01
  • 1
    http://stackoverflow.com/a/14850728/1331451 also looks like it could help. But that is even more monkey-patching. – simbabque Feb 01 '17 at 11:12
  • 1
    I'm pretty sure you'd have to change [this line](https://metacpan.org/source/LEEJO/CGI-4.35/lib/CGI.pm#L641) in your local CGI.pm. You could install one using local::lib and change it there. But monkey-patching that in seems too complicated. – simbabque Feb 01 '17 at 11:36
  • Ok thank you for your help. I'm getting JSON via POST and PUT and thought that I can get JSON via DELETE too. So maybe I have to think about my service and how it (should) work. Thanks! –  Feb 01 '17 at 12:00
  • 1
    Typically a DELETE would work on something like `DELETE /resource/`. That's straight forward just like GET. Both GET and DELETE don't need to take data in CRUD. They can have a query string though. – simbabque Feb 01 '17 at 12:02
  • Ahhh ok thanks! If I send the parameters like in GET (i.e. p=test) and do in Perl CGI->new()->param('p') than I get 'test'. Thank you !! –  Feb 01 '17 at 12:32
  • 6 minutes worth watching about CGI.pm https://www.youtube.com/watch?v=jKOqtRMT85s – Georg Mavridis Feb 01 '17 at 13:14
  • Yes but I run it under Apache2 mod_perl and I didn't get runnin Mojolicious so I decided to use CGI for the Parameters –  Feb 01 '17 at 14:03

0 Answers0