SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: RESTful?

  1. #1
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)

    Question RESTful?

    So are you using REST? if yes for which situations do you think the REST approach works the best?

  2. #2
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying out but remain slightly skeptical. I think I'm coming around but I'm still yet to see anybody talk about using it on anything but a simple app.

  3. #3
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Luke Redpath
    I'm trying out but remain slightly skeptical. I think I'm coming around but I'm still yet to see anybody talk about using it on anything but a simple app.
    what you are waiting for is exactly what I am looking for Luke!
    REST doesn't seem to be that popular...does it?

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RPC is definitely more popular then REST, though I do believe that REST was gaining popularity before it was made an option in Rails 1.2. If i'm not mistaken .NET supported it, faking HTTP's DELETE and PUT as well (Heard it during David Hansson's Rails keynote, someone mentioned .NET's implementation and how bad it's faking was.). Amazon's S3 also offers a REST interface, though that really wasn't the question.

  5. #5
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dark Tranquility
    what you are waiting for is exactly what I am looking for Luke!
    REST doesn't seem to be that popular...does it?
    It does seem to be in the Rails community. I appear to be in the minority of those who remain skeptical.

    Rails' PUT/DELETE faking is pretty simple really, its just a hidden form field in your form.

  6. #6
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)
    Even Vinnie doesn't seem to like it

  7. #7
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can think of many applications where REST works really well, but not of applications where it wouldn't work (applications that you'd use Rails for, not an online calculator for example). Does anyone have examples of applications where REST doesn't work?

  8. #8
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2
    I can think of many applications where REST works really well, but not of applications where it wouldn't work (applications that you'd use Rails for, not an online calculator for example). Does anyone have examples of applications where REST doesn't work?
    Applications that have to follow a strict workflow (as part of the business rules) probably aren't a great fit for REST.

  9. #9
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I like the concept of "simplify everything down to CRUD". I'm not 100% sold on the idea of having a REST API for every part of your webapp, but I also see it as of minor importance I guess.

  10. #10
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Luke Redpath
    Applications that have to follow a strict workflow (as part of the business rules) probably aren't a great fit for REST.
    Yes! Do you think it's a good idea to create a REST layer, and on top of that the actual application for the user? The workflow can be done by the topmost application, and you still have a REST API beneath that. You can then expose these APIs for users who want to create another front-end.

  11. #11
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, whatever front end you have, it *must* interface with the workflow.

    The important thing to remember about a workflow is that whilst it looks similar to a controller (i.e. it deals with the logic of where to go next) its actually part of the domain model. Any controller should simply delegate to the workflow to find out where to go next, then issue the redirect.

    You could conceivelbly CRUD a Workflow object, updating the workflow with any important data, I suppose.

    Code:
    class WorkflowController < ActionController::Base
      before_filter :load_workflow, :except => [:new]
      after_filter :persist_workflow, :except => [:update, :delete]
    
      def new
        @workflow = Workflow.new
      end
    
      def show
        redirect_to :action => 'new' if @workflow.nil? and return
        @workflow.invoke(params[:step])
        render :template => params[:step]
      end
    
      def update
        @workflow.update(some_data)
        if @workflow.complete?
          redirect_to :action => 'destroy' and return
        end
        redirect_to :action => 'show, :step => @workflow.next_step
      end
    
      def destroy
        @workflow.destroy
      end
    
      protected
        def persist_workflow
          @workflow.save
          session[:workflow_id] = @workflow.id
        end
    
        def load_workflow
          @workflow = Workflow.find(session[:workflow_id])
        end
    end


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
  •