restslimcanjs

RESTful Javascript frameworks and RESTful PHP frameworks


This is my first time trying to get into RESTful frameworks for Javascript and PHP. Specifically, they are the micro-frameworks CanJS for Javascript and Slim for PHP.

They each seem to map the 4 HTTP "verbs" (Get, Post, Put, Delete) to database CRUD operations.

So, in what cases would one use one over the other? In what cases would one use both in tandem?


Solution

  • Some of your code says to CanJS, "Please findOne of this Foo object; the ID is 1"

    CanJS models say to Slim services, "Hello, can I GET this object that you have at /foos/1 ?"

    Slim says "Sure, here's some text that represents it { BLAH BLAH BLAH }"

    CanJS and Slim agreed beforehand on what an object looks like, so when CanJS sees the text, it knows how to make an object out of it by parsing

    CanJS takes the text, parses it, makes something that looks like a Foo (Foo is a special type of can.Model that you made by subclassing) out of it, and sends it back to your code using a success callback or a resolved promise.

    When you use a framework on the client side that wraps around REST, you always need a matching service on the server side that provides REST endpoints (something to handle GET/POST/PUT/DELETE requests). So it's not a matter of choosing between CanJS and Slim, but a matter of choosing Slim versus something else to work together with (provide the data to) CanJS.