Coder Social home page Coder Social logo

Long polling example about plezi HOT 1 CLOSED

boazsegev avatar boazsegev commented on May 22, 2024
Long polling example

from plezi.

Comments (1)

boazsegev avatar boazsegev commented on May 22, 2024

Hi,

For a demo about RESTful Plezi controllers, you can look over the code for the StubRESTCtrl controller, which is just a stub used for testing.

Using Plezi for long pulling, without web socket support, is super easy.

Here's an outline (a full-fledged Plezi app would look very different):

class MyController
      # every request that routes to this controller will create a new instance
      def initialize
      end

      # called when request is GET and params[:id] isn't defined
      def index
            "Hello World!"
      end

      # called when request is GET and params[:id] exists
      def show
            "nothing to show for id - #{params[:id]} - with parameters: #{params.to_s}"
      end

      # called when request is GET and params[:id] == "new" (used for the "create new object" form).
      def new
            "Should we make something new?"
      end

      # called when request is POST or PUT and params[:id] isn't defined or params[:id] == "new" 
      def save
            "save called - creating a new object."
      end

      # called when request is POST or PUT and params[:id] exists and isn't "new"
      def update
            "update called - updating #{params[:id]}"
      end

      # called when request is DELETE (or params["_method"] == 'delete') and request.params[:id] exists
      def delete
            "delete called - deleting object #{params[:id]}"
      end
end
require 'plezi'
require 'pathname'

Root = Pathname.new(File.dirname(__FILE__)).expand_path

listen # root: Root.join('public').to_s,
       # assets: Root.join('assets').to_s,
       # assets_public: '/assets',
       # templates: Root.join('app','views').to_s,
       # ssl: false

route '/(:id)/(:value)', MyController

exit #only if using terminal

Now try visiting:

As to Rack and Grape:

Plezi isn't built to be Rack compatible - although it has a Rack adaptor for testing, Plezi is a Rack alternative.

I'm sorry to say that since Grape depends on Rack, Plezi will be an alternative to Grape and these two platforms will not be compatible.

Good Luck!

from plezi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.