4

I have this wish that so far Google hasn't been able to fulfill. I want to find a package (ideally in PHP, because I know PHP, but I guess that's not a hard requirement) that you point at a database, it builds an ORM based on what it finds there, and exposes a REST interface over the web.

Everything I've found in my searches requires a bunch of code--like, it wants you to build the classes for it, but it'll handle the REST request routing. Or it does database and relational stuff just fine, but you have to build your own methods for all the CRUD actions.

That's dumb. REST is well defined. If I wanted to re-invent the wheel, I totally could, but I don't want to. Isn't there somebody who's built a one-shot super-simple auto-RESTing web service package?

3
  • 1
    Reminds me of the promise of WCF-RIA in .NET. It was tooling that auto-generated an ORM model, then auto-generated a HTTP GET oriented service layer. It seemed like a good idea, but it had problems.
    – Kyle
    Apr 3, 2012 at 13:18
  • Rails is the closest thing I can think of. ActiveRecord would have to be configured to know the relationships between the tables, but it will automatically read the columns. A REST interface is provided by scaffolding. It's not zero work, but it's not much (unless the schema is very complex). Apr 3, 2012 at 19:06
  • Since you don't mind .NET tools, may be Telerik's Open Access can be useful to you. See: telerik.com/products/orm/features/… and Oxygen at: oxygencode.com/Features.html
    – NoChance
    Aug 20, 2012 at 4:13

4 Answers 4

2

As you say PHP is not a hard requirement, I hope it's okay to point to a Python solution: Django + django-tastypie will more or less do what you're asking for.

You can autogenerate the Django ORM classes from an existing database, and django-tastypie uses sensible defaults to expose each model using REST, only requiring a few lines of declaration for each ORM class you want to expose.

0

I think the answer to your question may well be "no". I've been lurking around the PHP trenches for about six years and, to date, have not stumbled across the type of thing you are looking for. It does seem like a fairly straightforward thing to build though, so it is a bit of a mystery why nobody has done it yet. Zend Framework, RedBean and a whole bunch of other frameworks with database table auto-discovery should provide a good basis for such a project.

0

The idea is not right. Your database storage is not directly related to the output. For example 2 models could use the same table without any problem. So to relate tables directly to output doesn't feel right to me.

You also miss the part of virtual fields for example. Say you have an invoice total. The model will attach it to the record so you won't find it when you just read the database. That's why there are layers in applications.

Better idea is to use a code generator to make the classes. I notice CakePHP was already mentioned, it's capable of that with scaffolding and bake. Maybe that will save you lots of time.

0

The closest thing in PHP (that I know of) to what you describe would be using CAKE. I personally don't like this framework so I'm definitely not an expert but you could build model using bake and add CRUD functionality with bake or using scaffolding so there will be no any codding involved.

And then just setup REST through routing. The main problem would the maintainability of such solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.