- Notifications
You must be signed in to change notification settings - Fork52
Webmachine, the HTTP toolkit (in Ruby)
License
webmachine/webmachine-ruby
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
webmachine-ruby is a port ofWebmachine, which is written inErlang. The goal of both projects is to expose interesting parts ofthe HTTP protocol to your application in a declarative way. Thismeans that you are less concerned with the procedures involved in handlingrequests directly and more with describing facts about the resourcesthat make up your application.Webmachine is not a web frameworkper se, but more of atoolkit for building HTTP-friendly applications. For example, it doesnot provide a templating engine or a persistence layer; those choicesare up to you.
- Handles the hard parts of content negotiation, conditionalrequests, and response codes for you.
- Provides a base resource with points of extension to let youdescribe what is relevant about your particular resource.
- Supports WEBrick and a Rack shim. Other host servers are being investigated.
- Streaming/chunked response bodies are permitted as Enumerables,Procs, or Fibers!
- Unlike the Erlang original, it does real Language negotiation.
- Includes a visual debugger so you can look through the decisiongraph to determine how your resources are behaving.
- How it works - understand how Webmachine works and the basics of creating a resource.
- Example resources showing how to implement each HTTP method.
- Routes
- Authentication and authorization
- Validation
- Error handling
- Visual debugger
- Configurator
- Webserver adapters
- Versioning APIs
- API documentation
- Mailing list
- IRC channel #webmachine on freenode
Below we go through some examples of how to do basic thingswith webmachine-ruby.
The first example defines a simple resource that doesn't demo thetrue power of Webmachine but perhaps gives a feel for how aWebmachine resource might look.Webmachine::Resource.run
is availableto provide for quick prototyping and development. In a real applicationyou will want to configure what path a resource is served from.See theRouter section in the README for more details on how todo that.
There are many other HTTP features exposed to a resource through{Webmachine::Resource::Callbacks}. A callback can alter the outcomeof the decision tree Webmachine implements, and the decision treeis what makes Webmachine unique and powerful.
require'webmachine'classMyResource <Webmachine::Resourcedefto_html"<html><body>Hello, world!</body></html>"endend# Start a web server to serve requests via localhostMyResource.run
require'webmachine'require'widget'classMyResource <Webmachine::Resource# GET and HEAD are allowed by default, but are shown here for clarity.defallowed_methods['GET','HEAD']enddefcontent_types_provided[['application/json',:to_json]]end# Return a Truthy or Falsey valuedefresource_exists?widgetenddefwidget@widget ||=Widget.find(request.path_info[:id])enddefto_jsonwidget.to_jsonendend
The router is used to map a resource to a given path. To map the classMyResource
tothe path/myresource
you would write something along the lines of:
Webmachine.application.routesdoadd['myresource'],MyResourceend# Start a web server to serve requests via localhostWebmachine.application.run
When the resource needs to be mapped with variables that will be passed into the resource, use symbols to identify which path components are variables.
Webmachine.application.routesdoadd['myresource',:id],MyResourceend
To add more components to the URL mapping, simply add them to the array.
Webmachine.application.routesdoadd['myparentresource',:parent_id,'myresource',:id],MyResourceend
Read more about routinghere.
There is a configurator that allows you to set what IP address and porta web server should bind to as well as what web server should serve awebmachine resource. Learn how to configure your applicationhere.
Webmachine provides adapters for many popular webservers. Learn morehere.
It can be hard to understand all of the decisions that Webmachinemakes when servicing a request to your resource, which is why we havethe "visual debugger". Learn how to configure ithere.
- webmachine-test - Helpers for testing Webmachine applications
- webmachine-linking - Helpers for linking between Resources, and Web Linking
- webmachine-actionview - Integration of some Rails-style view conventions into Webmachine
- jruby-http-kit - Includes an adapter for the Clojure-based Ring library/server
- newrelic-webmachine - NewRelic instrumentation
webmachine-ruby is licensed under theApache v2.0 license. SeeLICENSE for details.
About
Webmachine, the HTTP toolkit (in Ruby)
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.