Comments (1)
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:
- http://localhost
- http://localhost:3000/new
- http://localhost:3000/1
- http://localhost:3000/1/a%20random%20value
- http://localhost:3000/1?method=_delete
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)
- ERROR -- : uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable (NameError) HOT 10
- ERROR -- : incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError) HOT 11
- Documentation help needed. HOT 2
- WebSocket connection to 'ws://localhost:3000/ws' failed: Error during WebSocket handshake: Unexpected response code: 200 HOT 21
- JSON event length is limited HOT 10
- Server configs HOT 4
- download error with bundled client.js HOT 1
- rabbitmq HOT 1
- Finding a websocket session and send message HOT 8
- SyntaxError in generated config.ru
- Rack < 2.0 : cannot load such file -- rack/query_parser.rb HOT 1
- message_size_limit uninitialized constant Iodine::Http HOT 10
- create function is not synchronized HOT 19
- server shutdown when one or more client has a poor connection HOT 7
- Upgrade to bundler 2.0 HOT 3
- Help needed! HOT 1
- Failing at higher concurrency HOT 2
- Gap in documentation for serving static assets HOT 3
- Architectural clarification HOT 2
- There is no way to unsubscribe from Plezi::Controller.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plezi.