Do I need a framework to build a REST API in PHP?

I am fairly new to PHP (about 8 months). I am building a web app, which is almost ready for beta. I am only now starting to think about what I would need to do to make a mobile version of the app.

As I understand, I should be building a REST API (please correct me if I'm wrong). I am currently NOT using a PHP framework for my web app. Should I be?

Should I now begin using a framework so that I could more easily implement my API? Or can I build my API without any framework at all?


SHORT ANSWER No, you don't need a framework to achieve your goal.

BUT it will be really easier if you use a framework to manage your API. I suggest you to go for a lightweight framework and maybe you can convert easily your webapp to the framework too, having one "app" to return two different "things" (web stuff & API).

Take a look at Laravel, Laravel 4 based REST API or a list of popular php rest api frameworks that can be used to build one.


You certainly don't need any kind of framework to build a PHP REST API. REST is nothing more than a protocol convention built on top of HTTP. Since PHP can obviously handle HTTP requests, it has everything you need to build RESTful API's.

The whole point of frameworks is to handle common tasks and things that are otherwise tedious. REST API's are commonly built with PHP, so a plethora of frameworks exist. Personally, I would use a lightweight framework like slim simply to handle things like URI routing, parsing/cleaning request data, and generating responses.