Sha256: 8dbffa4a2e5b96d3c70c0a29c2612de7981fa8e207ac32c48ad80ac2f969eb49

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

# Alf::Rack

[![Build Status](https://secure.travis-ci.org/alf-tool/alf-rack.png)](http://travis-ci.org/alf-tool/alf-rack)
[![Dependency Status](https://gemnasium.com/alf-tool/alf-rack.png)](https://gemnasium.com/alf-tool/alf-rack)
[![Code Climate](https://codeclimate.com/github/alf-tool/alf-sql.png)](https://codeclimate.com/github/alf-tool/alf-rack)

A collection of Rack middlewares for using Alf in web applications.

## Links

* http://github.com/blambeau/alf
* http://github.com/blambeau/alf-rack

## Example: a RESTful-like interface

**See the examples folder for more advanced examples.**

```
require 'sinatra'
require 'alf-rack'

# include some helpers (see later)
include Alf::Rack::Helpers

# This middleware will open a database connection on every request.
# That connection and query methods are available through the helpers.
use Alf::Rack::Connect do |cfg|
  cfg.database = ::Sequel.connect("postgres://...")
end

# Let send all suppliers, automatically use HTTP_ACCEPT to encode in
# requested format (csv, json, etc.)
get '/suppliers' do |id|
  Alf::Rack::Response.new{|r|
    r.body = relvar{ suppliers }
  end
end

# Similar for a single supplier tuple
get '/suppliers/:id' do |id|
  # Find the supplier
  Alf::Rack::Response.new{|r|
    r.body = tuple_extract{ restrict(suppliers, sid: id) }
  end
end
```

## Example: arbitrary queries

```
# As before
use Alf::Rack::Connect do |cfg|
  cfg.database = ::Sequel.connect("postgres://...")
end

# Answers arbitrary queries on POST /
run Alf::Rack::Query.new
```

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-rack-0.16.3 README.md
alf-rack-0.16.2 README.md
alf-rack-0.16.1 README.md
alf-rack-0.16.0 README.md
alf-rack-0.15.0 README.md