Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 218
Progger Avatar asked Jun 29 '12 21:06

Progger


People also ask

Can we make REST API in PHP?

Create the Model/Database. php file with the following contents. This is a database access layer class, which allows us to set up a connection to the MySQL database. Apart from the connection setup, it contains generic methods like select and executeStatement that allow us to select records from a database.

Do you need a framework for PHP?

Why use a PHP framework? A PHP framework provides a basic structure for streamlining the development of web apps. We use them because they speed up the development process. Above all, the responsiveness of websites and applications built using PHP frameworks helps businesses fulfill their performance needs.

Is REST API a framework?

The REST API is part of the integration framework and handles requests from external consumers. The following diagram provides an overview of how the REST API handles requests. When an external consumer initiates a request, a REST API controller directs the resource request to the appropriate resource handler.

Which PHP framework is specifically created for building REST web services?

PHP REST API: Lumen Lumen is a micro-API framework made out of Laravel. Specially designed for building REST APIs, this framework cuts off all Laravel features that restrict stateless APIs. Instead, it focuses on what is useful to REST APIs. This is why Lumen is such a lightweight framework.


1 Answers

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.

like image 157
napolux Avatar answered Oct 05 '22 06:10

napolux