Search code examples
phprestler

Using RESTler, can I name a method something different than post() or postSomething() when it must accept arguments via an HTTP post?


I'm considering using Lucarast RESTler (http://luracast.com/products/restler/)

My PHP class has a method called 'solve' and it must accept an argument via POST

class Solver
{
  function solve( $request_data )
  {
    ...
  }

If I simply name the method "solve", it can't be accessed via POST. I get 404.

POST http://localhost/path/to/my/method 404 (Not Found)

Apparently I have to name it "postSolve", that works. Or create another method called "postSolve" that simply calls "solve".

public function postSolve( $request_data )
{
    return $this->solve( $request_data );
}

But I can't stop thinking there must be an elegant way of doing this.

How can I call my method whatever I want, and still make it accessible via POST?


Solution

  • I learned a bit more about REST in the past few days. I shouldn't be needing methods called anything other than get, post, put, or delete.

    Please refer to this other question: Understanding REST: Verbs, error codes, and authentication

    "In general, when you think you need more verbs, it may actually mean that your resources need to be re-identified. Remember that in REST you are always acting on a resource, or on a collection of resources. What you choose as the resource is quite important for your API definition."