SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Best api framework

    What php framework is best suited for a scalable rest api-service?

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    One that is minimal. I am about to look at slim framework to compare it against my PHPRouter (don't use my router for production yet). You don't need something like Zend or CodeIgnitor that adds a bunch of layers you don't need (mvc for example)

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,146
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    There isn't really any reason why you couldn't use the complete Symfony 2 stack or cherry pick specific components like the router for a such a task. I guess it would partially depend on the business purpose of the API. Using Symfony/components any loss in performance you will make up in maintainability, support, dependability, scale, and general code quality.

    I'm always skeptical of projects that compare themselves to others on the basis of performance. Judging performance is bias unless the two applications/code bases do the same same exact thing meeting all the business requirements of a specific project. Though performance comparisons always tends to be based on the simplest business requirements that would rarely if ever fulfill the needs of a real-world project in continuous development.

    To that end I recommend maintainability, support, and code quality as the driving factors behind choosing a framework, cms, or any other open rather than performance. Unless the business requirements are very out of the ordinary the major performance bottlenecks will always be interacting with other services. Attempts to add micro-optimizations in other places tend to be a waste of time and offset by future changes. You are better off implementing caching strategies when problems arise than micro-optimizing especially when it comes to software that is in continuous development.

    That is why I would recommend a framework like Symfony or to cherry pick components as opposed to using some random project by a single individual that will most likely be abandoned all to soon because they move onto the "next big thing". With large projects like Symfony there is a very slim chance the project will be dropped. There is a high chance certain versions will not be supported in distant future. However, death of versions naturally happens in the open source life cycle.
    The only code I hate more than my own is everyone else's.

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    IMO, code quality can degrade when you try to cram a REST API into an existing MVC framework. A REST API doesn't need a view, view helpers or most other features that comes with it. Most APIs will be performing a simple task of connecting to a DB and running some sort of operation, and return that result. This can be achieved with so much less code and overhead. Developing without a framework shouldn't be viewed as a scray thing, nor should it be viewed as a bad thing as long as you still use good design practices (and this does not mean what is commonly viewed as PHP's good design practices)

  5. #5
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I agree, that code quality can degrade when you try to develop a REST API with a MVC framework. But lightweight is not the most important requirement for me.

    Is there any mature php rest api framework with includes all important api functionality (authentication, caching, etc)?

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    What type of authentication are you looking for?

  7. #7
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I must admit, that I have not decided yet on authentication method

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    It's probably worth mentioning that Symfony2 that oddz recommended earlier doesn't identify itself as an MVC framework. It's a Request/Response framework, and it doesn't force you to cram your code in any way you don't like. You can use a view layer or not; it's optional. You can use an ORM or not; it's optional. You also get built-in authentication (using whatever method you like... basic http, html forms, via Twitter, whatever), built-in caching, built-in validation, among lots more. It's also testable, it encourages writing DRY code, it has a large community, so on and so forth.
    "First make it work. Then make it better."

  9. #9
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    I'm getting the impression that MVC is being equated with something resource-intensive or only for "complex" apps.. Surely, even when building something as "simple" as a REST API you'd want to maintain a basic separation of concerns? Even APIs grow, and the requirements change.. and it's still going to be easier to maintain if you don't have persistence logic mixed in with display logic, right?

  10. #10
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    I'm getting the impression that MVC is being equated with something resource-intensive or only for "complex" apps.. Surely, even when building something as "simple" as a REST API you'd want to maintain a basic separation of concerns? Even APIs grow, and the requirements change.. and it's still going to be easier to maintain if you don't have persistence logic mixed in with display logic, right?
    Very good point! Times like this I wish SitePoint had an upvote feature.
    "First make it work. Then make it better."

  11. #11
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by fretburner View Post
    I'm getting the impression that MVC is being equated with something resource-intensive or only for "complex" apps.. Surely, even when building something as "simple" as a REST API you'd want to maintain a basic separation of concerns? Even APIs grow, and the requirements change.. and it's still going to be easier to maintain if you don't have persistence logic mixed in with display logic, right?
    MVC its self really isn't all that resource intensive, its what usually comes with it. Certain small operations / tweaks to get the request ready. When dealing with a REST API, for me anyway, small increases in page load time is a huge deal. If I can get another 3 requests in per second, when running a client that is making 30 simmultanous calls to the API at a time, you now have a gain of almost 100 requests a second.

    You'd be suprised how easy it is to keep an API project clean without "seperation", which I'm assuming you mean the model and controller. Your seperation comes from one class per file.

  12. #12
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can also look into apigility which gives you a GUI to create an API. Its built on top of Zend Framework 2 & made by Zend. If you're looking at micro-frameworks then take a look at Silex as well, it has been built using Symfony components by the makers of Symfony framework.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  13. #13
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by asp_funda View Post
    You can also look into apigility which gives you a GUI to create an API. Its built on top of Zend Framework 2 & made by Zend. If you're looking at micro-frameworks then take a look at Silex as well, it has been built using Symfony components by the makers of Symfony framework.
    ZF2 has done horribly in many benchmarks. Like, really bad. I wonder if apigility strips any of it out.

  14. #14
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    ZF2 has done horribly in many benchmarks. Like, really bad. I wonder if apigility strips any of it out.
    I usually take most benchmarks with more than a pinch of salt as barring few exceptions (where the reviewer or the person benchmarking the frameworks know well enough about all or most of them) all benchmarks done are with "Hello World" skeleton apps which present a very skewed picture. I mean its common sense that in such a benchmark a micro framework would score better than almost all full stack frameworks, heck, a simple PHP file with just "echo 'Hello World';" would score best.

    I agree ZF2 doesn't have much of a stellar reputation. I'm not sure if they've improved anything in apigility or removed unnecessary stuff. I've just played with it for a very short while, someone at work mentioned it to me so I installed it to see whats it about. But the idea is quite intriguing, an app which lets you make APIs quickly, definitely worth checking out in detail.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  15. #15
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by asp_funda View Post
    I mean its common sense that in such a benchmark a micro framework would score better than almost all full stack frameworks, heck, a simple PHP file with just "echo 'Hello World';" would score best.
    Hello World get's you the base overhead of the framework. I've seen several benches done against more ocmmon frameworks (ZF1, ZF2, CI, etc) and ZF2 was at the bottom. If I remember correctly, ZF2 was somewhere around 5 to 10 times slower than ZF1.


    Quote Originally Posted by asp_funda View Post
    But the idea is quite intriguing, an app which lets you make APIs quickly, definitely worth checking out in detail.
    Absolutely. Every API doesn't have to have great performance.

  16. #16
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,146
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    If you are concerned about performance and are in a dedicated hosting environment perhaps this would be a great opportunity to check of Phalcon. I haven't used it myself but nothing is going to be faster than a php extension itself. Not to mention having looked over the docs I'm quite impressed. It seems like they have taken all the good parts of popular frameworks like Symfony and bundled them into a PHP extension. Also, the documentation looks pretty thorough. The framework also has a concept of a "Mini" application which would be perfect for something like a RESTful API without a client-side front-end. I recommend checking it out if possible, I surely would try it out in a project if given the opportunity.
    The only code I hate more than my own is everyone else's.

  17. #17
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Phalcon looks cool. Has anyone used it for building a REST-ful API? (I have searched on github without any luck)

  18. #18
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kohana and cakephp


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •