Čamo
Čamo

Reputation: 4192

Restler can not process URL with dot and returns 404

I need to call URL https://xxx.xxx.com/xxx/image/upload3/w_300/v1675261380/nvrzhquqawhrkxlex6le.jpg
I have an endpoint on Restler which looks like this:

/**
 * image api
 *
 * @status 200
 * @url GET xxx/image/upload3/{params}/{dir}/{id}
 *
 * @param mixed $params {@from path}
 * @param mixed $dir {@from path}
 * @param mixed $id {@from path}
 *
 * @return mixed
 *
 * @throws RestException
 */
public function screenshot($params, $dir, $id)
{
    die('xxx');
    $this->showImage($params, $dir, $id);
}

But Restelr returns 404 before the function screenshot() is called and die('xxx') never run. If I remove the .jpg from URL it works so I am pretty sure the problem is in the .jpg suffix. I tried to use {@patern} param but it is the same.

Upvotes: 1

Views: 47

Answers (1)

TSCAmerica.com
TSCAmerica.com

Reputation: 5417

I uses a wildcard pattern in your route configuration to capture everything in the $id parameter, including the .jpg extension, see if this helps

/**
 * image api
 *
 * @status 200
 * @url GET xxx/image/upload3/{params}/{dir}/{id}
 *
 * @param mixed $params {@from path}
 * @param mixed $dir {@from path}
 * @param mixed $id {@from path} {@pattern /[\w\-\.]+/}
 *
 * @return mixed
 *
 * @throws RestException
 */
public function screenshot($params, $dir, $id)
{
   die('xxx');
  $this->showImage($params, $dir, $id);
}

Upvotes: 1

Related Questions