Search code examples
apirestcakephpodata

How to render json without having .json at the end of the url


I want to implement ODATA formatting to my CakePHP REST API. My problem is CakePhp expects .json at the end of the resource to understand the response format.

How can I render json and remove ".json" part from my request url?

I.e.

Current GET:

api.local/api/v2_agent_properties/83.json

Target GET:

api.local/api/v2_agent_properties(83)

Solution

  • you could set this in the beforeRender of the appController:

    $this->RequestHandler->renderAs($this, 'json');