Jonathan Bouchard
Jonathan Bouchard

Reputation: 443

How to use CakePHP exclusively for the API?

I have a API made with CakePHP and I don't want to use the views to display something on the website, for example I'd like to be able to use api.mydomain.com/users in CURL, but if I try to go to the URL in my browser I want it to redirect to api.mydomain.com which will be my API documentation. I want this to be for every controller.

I don't know if my question is clear, but I only want my site to serve JSON responses and nothing else. If there's a better solution to my question, I'd like to hear it too.

Thanks for helping.

Upvotes: 3

Views: 85

Answers (1)

SamHecquet
SamHecquet

Reputation: 1836

You need to use JSON and XML views. In this way, you'll render a JSON response.

I don't think you should redirect to the api.mydomain.com, it's pretty common to access API through a browser, but if you really want to do it you have to take a look at $_SERVER['HTTP_USER_AGENT'] variable

Upvotes: 1

Related Questions