slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.96k stars 1.95k forks source link

Proposition for making SLIM RESTful #681

Closed ghost closed 10 years ago

ghost commented 10 years ago

Currently SLIM framework has only REST level 2 support. It helps by routing via http verbs and methods, but it does not help by making resource relations and building hypermedia representations (json-ld, hal+json, atom+xml, siren, ...), etc... REST level 3 (RESTful in other words) means support of the HATEOAS principle, and represent resources and their relations with hypermedia (eg html, hal+json, etc...), not just the data part of resources with a data format (eg json, xml, etc...).

I searched a lot and I have found only a single PHP bundle: Hydra Symfony2 Bundle which supports REST level 3 yet. So this feature is very rare currently, because it is hard to understand, and even harder to design a good interface for it. If you could implement this feature well, then it would make SLIM much more popular... If you are not familiar with this topic, please read articles about HATEOAS, RESTful-ness, hypermedia API, hypermedia media types. I suggest to study the approach of hydra as well, I think you can learn a lot from that.

Another thing is data modeling, it is possible to use standard/recommended data models with the actual hypermedia type, for example: microformats2, microdata with existing schemas, etc... If you would use something like this, the REST client applications would be completely exchangeable without any modifications on the REST service, so this would improve interoperability as well.

So I suggest to implement a way to model resources and resource relations, and after that implement hypermedia support to automatically represent those linked resources on the language of the selected hypermedia type. After that I suggest to implement data model support to automatically represent resource properties in a standard way. With these new features it would be much easier to build a RESTful webservice with SLIM.

I am currently experimenting with hydra, but I don't like the heavy weight of Symfony2. If I am not satisfied with those, I'll create a proof of concept application with SLIM, and maybe after that with lot of refactoring, I can create something general in this topic... Maybe you can do more about this, that's why I wrote this proposition.

codeguy commented 10 years ago

I feel like this would merit its own separate component that could be used within a Slim (or Silex or Laravel or Symfony or...) application. But I don't see Slim itself being able to implement this without forcing specific conventions on applications built with Slim. I agree it would be nice to have a tool to handle this complex and confusing task, but it won't be in Slim core. I do encourage you to build this out as a separate stand-alone component.

ghost commented 10 years ago

I will sooner or later...

lplume commented 10 years ago

Perhaps a standalone component maybe wrapped in a middleware?

ghost commented 10 years ago

I'll create a separate framework with a SLIM adapter...