0

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?

Arul Kumaran
  • 983
  • 7
  • 23
JulianG
  • 4,265
  • 5
  • 23
  • 24

2 Answers2

2

Auto routing requires you to prefix the api method names with get or post or put or delete to map it to the respective HTTP method/verb

More on this at this example

But you can always use a PHPDoc comment in the following format above the api method to map any method to POST

@url POST my/custom/url/:myvar

For example

class CustomPost
{
    /**
     * @url POST custom/:id
     * @url GET custom
     */
    function anyName($id)
    {
        //do something
    }
}
Charm_quark
  • 376
  • 2
  • 6
  • 30
Arul Kumaran
  • 983
  • 7
  • 23
1

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."

Community
  • 1
  • 1
JulianG
  • 4,265
  • 5
  • 23
  • 24