Skip to content

lfe-http/barista

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

barista

Build Status LFE Versions Erlang Versions Tags Downloads

Barista serves up hot lmugs of LFE for your simple LFE-native HTTP needs.

Contents

Introduction

Barista is a stand-alone, simple HTTP server. Or more accurately, barista is LFE code that wraps the Erlang/OTP httpd HTTP server. It is intended for development/demo purposes and non-critical services.

Installation

Just add it to your rebar.config deps:

    {deps, [
        {barista, "0.3.3"}
    ]}.

And then do the usual:

    rebar3 compile

Usage

To try out the default no-op/pass-through handler, you can do this (after rebar3 compile):

rebar3 lfe repl
lfe> (set `#(ok ,svr) (barista:start))

This will start an HTTP server with the default barista options. You can use curl to try it out:

curl "http://localhost:5099/"

or

curl -XPOST \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "c=3&d=42" \
     "http://localhost:5099/order?a=1&b=2"

You can override the default options like so:

lfe> (set `#(ok ,svr) (barista:start '(#(port 9099))))

Additionally, you can provide a config file that may be used to provide options for starting up barista (which is really the inets httpd service):

lfe> (set `#(ok ,svr) (barista:start '(#(config-file "configs/sys.config"))))

That expects the inets httpd configuration to be in a nested proplist under the following:

[{inets,
 [{services,
  [{httpd, ... }]}]}].

If your configuration is in a different part of the configuration, you just need to supply a list of the keys that point to it, e.g.:

lfe> (set `#(ok ,svr) (barista:start '(#(config-file "configs/sys.config")
                                       #(config-keys (my-app httpd)))))

Finally, to stop barista:

lfe> (barista:stop svr)

Creating Custom Modules

The Erlang inets httpd server supports the creation of modules (see the documentation for the various mod_* httpd modules). The example module barista-passthrough implements the httpd module contract: a single do/1 function is all that is needed. The argument it takes is the inets httpd request record mod found in inets/include/httpd.hrl.

In addition to this, the barista-passthrough defines a handle/3 function very much in line with the sort of thing that Elli developers do when creating routes for their web applications.

License

Copyright © 2014-2021, Duncan McGreggor

Apache License, Version 2.0

About

Barista serves up hot lmugs of LFE for your simple HTTP needs.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors