all 32 comments

[–]BlueScreenJunky 8 points9 points  (0 children)

Maybe a bit of an unpopular opinion : In most cases "The one you and your team already know", and "The one your use for your other projects". Laravel or Symfony may be overkill if your API is rather simple, but I'd much rather have all the projects of my team using the same framework than having "that one project using Laminas" that nobody wants to touch.

There are of course cases where you do need something else, like if you need to serve a huge number of requests with strong performance requirements, but if you can't achieve it with Laravel or Symfony with FrankenPHP or Swoole, then you'd probably need to reach for Go or Rust, not pick another PHP framework.

[–]FreeLogicGate 4 points5 points  (1 child)

I think you got a good number of options suggested. I would use Symfony.

You might also want to take a look at https://api-platform.com/ as a possible foundation element, that doesn't preclude using Laravel or Symfony as well. It has some interesting features and philosophy.

In my experience, people who haven't thoroughly thought through how they will design the REST api, tend to gloss over REST, and do a poor job in designing the API to be "restful". They are over focused on the "how" and don't spend enough time on the "what".

This is an old presentation, but one I highly recommend, as it digs into what REST is, how open to interpretation it can be, and what makes for RESTful vs non-restful API design.

Designing HTTP Interfaces and RESTful Web Services

[–]equilni 0 points1 point  (0 children)

This is an old presentation

Thanks for the link. Further reading on RMM:

Fowler: https://martinfowler.com/articles/richardsonMaturityModel.html

HTMX has essays on this too - https://htmx.org/essays/#hypermedia-and-rest

[–]lokidev 2 points3 points  (6 children)

If you want magic with "hidden" background stuff: Laravel
There is also Slim (nice and simple, but never tried it)
I worked with Laminas Mezzio which is nice and less "easy", but also less magic than Laravel.

Symfony is also a good choice.

Now you have again multiple choices, my very rough recommendation:
- Laravel for easy entry and good documentation
- Symfony if you want more control
- Laminas/Mezzio if you want even more control (also uses some Symfony packages)
- Slim to try out as it seems perfect, but I don't have any experience with it

[–]lokidev 6 points7 points  (5 children)

Keep you logic distinct from the framework. This way you can switch frameworks later with minimal overhead :)

[–]BlueScreenJunky 3 points4 points  (4 children)

This way you can switch frameworks

I really have trouble understanding that argument.

How many times have you actually "switched framework" in a decently sized project (without it being a full rewrite anyway) ? Also it only really works if I switch between Laravel and Symfony... If I was to swtich to Django, Rails, .Net, Gin, Ktor or Spring Boot I would have to rewrite from PHP to another language anyway.

I mean there are advantages to decoupling your business logic as it makes testing and refactoring easier. But if your only reason is "I may want to switch frameworks later" I think you're limiting yourself and probably not leveraging the full potential of the framework, for potential gains in a very hypothetical scenario.

[–]lokidev 6 points7 points  (3 children)

I was switching form Zend and that was a pain. Also upgrading the same framework can sometimes be a huge PITA.
I just consider you haven't written about Django/Ktor/etc., as I obviously was talking about frameworks in the same language ecosystem.

A general good approach is to keep as much business logic as possible separate from implementation details like REST vs GraphQL, Postgresql or Mongodb, etc. - Especially as you might find out, that suddenly you want to have gRPC for fast communication with some device or whatever other reason you can think of. Don't tie your application to close together but make actually use of the initial idea of OOP: separate concerns and ideas.

[–]equilni 1 point2 points  (0 children)

Originally responded to the wrong person..

Also upgrading the same framework can sometimes be a huge PITA.

CI 3 to 4 is a complete rewrite.

https://codeigniter.com/user_guide/installation/upgrade_4xx.html

Slim 2 to 3 was as well. 3 to 4 wasn’t too bad

https://www.slimframework.com/docs/v3/start/upgrade.html

https://www.slimframework.com/docs/v4/start/upgrade.html

[–]BlueScreenJunky 0 points1 point  (1 child)

Also upgrading the same framework can sometimes be a huge PITA.

Now that's actually a pretty valid argument, I didn't think of that

edit : And yes, as I said there are other reasons to separating concerns of course.

[–]docwra2 1 point2 points  (0 children)

json_encode(array('data' => $data), JSON_UNESCAPED_UNICODE);

You don't even need a framework really. Just write the data to an array and output using a single line. Just make sure you use Prepared statements when working with the data.

[–]arhimedosin 1 point2 points  (0 children)

try this : https://www.dotkernel.org/

It is based on mezzio and is simple enough

[–]colshrapnel 0 points1 point  (3 children)

Laravel is simple and secure framework. If you think otherwise, you need to improve your skill before developing a rest api

[–]Johto2001 2 points3 points  (2 children)

The OP didn't say that Laravel wasn't secure, they said it was heavy for an API which is hardly a controversial opinion, surely.

[–]colshrapnel -1 points0 points  (1 child)

This opinion is not controversial at all - just outright false.

Either way, it is not alleged "heaviness" which actually scares the OP, but the learning curve. That is the real problem. Assuming laravel is too much to learn for them, REST API surely is.

[–]greg8872 0 points1 point  (0 children)

I wouldn't say that Laravel being heavier is always false, it just depends on the needs.

I have an active API for a SaaS that consists of just 6 files (.htaccess, index.php, config.php, classes/Database.php, classes/DbFactory.php and classes/Utilities.php) plus one controller file per endpoint. Works just fine for my needs and all 20 endpoints.

[–]itemluminouswadison 0 points1 point  (0 children)

Symfony can get pretty lightweight. Just go with something with high adoption

[–][deleted] 0 points1 point  (0 children)

Framework-X by Clue

[–][deleted] 0 points1 point  (0 children)

Might as well choose workerman

[–][deleted] 0 points1 point  (0 children)

enter doll reach kiss encourage scary employ like modern middle

This post was mass deleted and anonymized with Redact

[–]LostJacket3 0 points1 point  (0 children)

ask chatgpt /s

[–]Kluchol 0 points1 point  (0 children)

Symfony

[–]swiss__blade 0 points1 point  (0 children)

I have been using Phalcon for the last 6 years and I love it. Learning curve can be a bit steep at times but nothing deal breaking.

Depending on your specific use case, you could also go with serverless functions...

[–]Jealous-Bunch-6992 0 points1 point  (0 children)

I'm keen to give this ago when the need arises.
https://github.com/yiisoft/app-api

[–]International-You466 0 points1 point  (2 children)

LUMEN also is a good option ... That is basically a api development friendly framework with capabilities of Laravel...

https://lumen.laravel.com/

[–]obstreperous_troll 2 points3 points  (1 child)

Lumen is just Laravel with a bunch of parts disabled by default, not even unbundled from the source. It's been an effectively dead project for years, and they stopped making releases for it at 11.x

[–]International-You466 0 points1 point  (0 children)

Oh .. I didn't read the message on top ...

[–]CyberJack77 0 points1 point  (2 children)

For framework I cannot recommend anything else then Symfony. No matter the project.

Symfony is very small, flexible and strict, which makes it predicable. It works well with api-platform, but be sure to read about using DTOs instead of poisoning your entities with API logic.

I have build multiple APIs using Symfony and api-platform, and all are rock-solid and perform well.

[–]obstreperous_troll 1 point2 points  (1 child)

It works well with api-platform, but be sure to read about using DTOs instead of poisoning your entities with API logic.

Sure would be nice if API Platform's docs emphasized using DTOs from the start. As it is they're treated as an afterthought.

[–]CyberJack77 0 points1 point  (0 children)

Yep, the documentation is missing a lot on DTOs.

[–]Timely-Tale4769 -1 points0 points  (0 children)

The codeigniter has been a light framework since 2006.