Elli support for LFE lanes


License
Apache-2.0

Documentation

lanes

Build Status LFE Versions Erlang Versions Tags

A slightly more general LFE HTTP routing library than lfest

Introduction

The lanes project aims to offer some of the YAWS-specific features of the lfest project to a wider selection of BEAM-based web servers. This is done with the understanding that the original design of lfest (and thus the design inherited in the lanes project) is not optimal.

For now, though, we are focused on the immediate and practical needs of LFE application developers.

Dependencies

  • Erlang 20+
  • rebar3

Compatibility

Releases of Elli map to the following versions in its dependencies:

  • 0.3.0 - LFE 2.1.1, Erlang 20-26, Rebar 3.22, rebar2_lfe 0.4.2 (with examples using logjam 1.0.5, Elli 3.3.0, Barista 0.3.2)
  • 0.2.0 - LFE 2.0.1, Erlang 20-25, Rebar 3.16, rebar3_lfe 0.3.1 (with examples using logjam 1.0.0, Elli 3.3.0, Barista 0.3.2)

Usage

Create your application/service routes with the (defroutes ...) form. Here is an example that is compatible with Elli:

(include-lib "lanes_elli/include/macros.lfe")

(defroutes
  ;; top-level
  ('GET #"/"
        (lanes.elli:ok "Welcome to the Volvo Store!"))
  ;; single order operations
  ('POST #"/order"
         (progn
           (lanes-elli-data:create-order (lanes.elli:get-data req))
           (lanes.elli:accepted)))
  ('GET #"/order/:id"
        (lanes.elli:ok
         (lanes-elli-data:get-order id)))
  ('PUT #"/order/:id"
        (progn
          (lanes-elli-data:update-order id (lanes.elli:get-data req))
          (lanes.elli:no-content)))
  ('DELETE #"/order/:id"
           (progn
             (lanes-elli-data:delete-order id)
             (lanes.elli:no-content)))
  ;; order collection operations
  ('GET #"/orders"
        (lanes.elli:ok
         (lanes-elli-data:get-orders)))
  ;; payment operations
  ('PUT #"/payment/order/:id"
        (progn
          (lanes-elli-data:make-payment id (lanes.elli:get-data req))
          (lanes.elli:no-content)))
  ('GET #"/payment/order/:id"
        (lanes.elli:ok
         (lanes-elli-data:get-payment-status id)))
  ;; error conditions
  ('ALLOWONLY ('GET 'POST 'PUT 'DELETE)
              (lanes.elli:method-not-allowed))
  ('NOTFOUND
   (lanes.elli:not-found "Bad path: invalid operation.")))

For full context, be sure to see the code in ./examples.

Consuming Routes

The following frameworks/HTTP servers are targetted by lanes, with the goal that each will be able to consume the routes defined by lanes:

License ↟

Apache Version 2 License

Copyright © 2014-2023, Duncan McGreggor oubiwann@gmail.com