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

PhpFrameworksRest

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

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.

Solution 3 - Php

No you do not need a framework to build a REST API, but it is highly recommended, as a well built framework can take care of things that can be very difficult and complicated otherwise, namely session authentications and caching and well separated architecture. Reinventing the wheel only gets you so far.

I'm a developer of Wave Framework which was developed keeping in mind an API-centric design (read more here). I encourage you to take a look into this framework and see if it might be something that could help you. It has a small group of developers, but it is slowly gaining recognition.

I encourage you to take a look at that and if it might fill your needs.

Solution 4 - Php

There are also tools that create a REST api from the DB without the need for extra code.

If you are using Postgres there is the excellent program postgREST that

> serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API than you are likely to write from scratch.

Solution 5 - Php

NO, YOU DON'T NEED ANY FRAMEWORK FOR PHP BACKEND.

If you are using php as backend then you don't need to use any resetAPI framework. Just create you own php files and generate JSON output for each response.

You must generate JSON output. That is enough. Benefits:- If you use own login to generate Json output then it will be tremendous light speed (based on your logic). If you use any framework then the performance issues will occure.

It will be better if you can design your own mini framework to do specific site's work.

Thanks

Solution 6 - Php

REST is more of a design ideology than a language framework, so NO you don't NEED to use any framework. However there is no advantage in reinventing the wheel (Sure some disadvantages are there like security, structure etc.).

If you want to avoid mayhem of MVC (which is not required specification of a REST architecture) you can use any PHP mico-framework (Slim, Lumen etc) they are really quick to learn and implement and allow PHP developer to write route based app (similar to those of MEAN and Express) saving a lot in time.

Most of these frameworks comes with an MVC as well but if you don't want to give a CMS for the API, MR (Model-Routes) is good enough (and practically the best) for all REST needs.

Since the dawn of angular like frameworks which allows your website to communicate with sever like any other API easily, I think even the CMS should access the API like any other app just with elevated rights or specific end-poin

Solution 7 - Php

The World is very very big, so, no one can do all things alone. Someone will help someone (who do something new) do something old. This is reason, libray and FW exist in our IT World.

In production/live environment, anything is very more complex than we think. Until a day in future, we will need to build so many thing for our project, and we will see that those things has been built by FW completely before.

Although just a RESTful Server, with pure PHP, we need resolve problems with: URI routing, parsing/cleaning request data, data access, dependency management, generating responses, bla bla bla...

I recommend using Slim or Phalcon (Micro App). Slim is a easy and quickly method, but Phalcon is a effective and high performing method.

Solution 8 - Php

Not necessarily, you don't really need a framework for anything! The framework is made just to provide you with tools to help building your projects faster. These days in most cases it is smarter to use a framework, cause who likes to reinvent the wheel!

Since you are a PHP developer and the best answer suggests to take a look Laravel, I would also suggest that you to take a look at Apiato (apiato.io), this is a PHP API framework built on top of Laravel. It lets you create your API way faster than starting with a vanilla Laravel, as it provides you with tens of features that you already need for every API.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionProggerView Question on Stackoverflow
Solution 1 - PhpnapoluxView Answer on Stackoverflow
Solution 2 - PhpDan SimonView Answer on Stackoverflow
Solution 3 - PhpkingmapleView Answer on Stackoverflow
Solution 4 - PhpAlexis PanagiotopoulosView Answer on Stackoverflow
Solution 5 - PhpKrishan KumarView Answer on Stackoverflow
Solution 6 - PhpHimanshu VaishnavView Answer on Stackoverflow
Solution 7 - PhpDekaView Answer on Stackoverflow
Solution 8 - PhpMahmoud ZaltView Answer on Stackoverflow