Git Product home page Git Product logo

elli's Introduction

elli - Erlang web server for HTTP APIs

Hex.pm Documentation Erlang Common Test Coverage Status MIT License

Elli is a webserver you can run inside your Erlang application to expose an HTTP API. Elli is aimed exclusively at building high-throughput, low-latency HTTP APIs. If robustness and performance is more important than general purpose features, then elli might be for you. If you find yourself digging into the implementation of a webserver, elli might be for you. If you're building web services, not web sites, then elli might be for you.

Elli is used in production at Wooga and Game Analytics. Elli requires OTP 18.0 or newer.

Installation

To use elli you will need a working installation of Erlang 18.0 (or later).

Add elli to your application by adding it as a dependency to your rebar.config:

{deps, [
  %% ...
  {elli, "3.0.0"}
]}.

Afterwards you can run:

$ rebar3 compile

Usage

$ rebar3 shell
%% starting elli
1> {ok, Pid} = elli:start_link([{callback, elli_example_callback}, {port, 3000}]).

Examples

Callback Module

The best source to learn how to write a callback module is src/elli_example_callback.erl and its generated documentation. There are a bunch of examples used in the tests as well as descriptions of all the events.

A minimal callback module could look like this:

-module(elli_minimal_callback).
-export([handle/2, handle_event/3]).

-include_lib("elli/include/elli.hrl").
-behaviour(elli_handler).

handle(Req, _Args) ->
    %% Delegate to our handler function
    handle(Req#req.method, elli_request:path(Req), Req).

handle('GET',[<<"hello">>, <<"world">>], _Req) ->
    %% Reply with a normal response. `ok' can be used instead of `200'
    %% to signal success.
    {ok, [], <<"Hello World!">>};

handle(_, _, _Req) ->
    {404, [], <<"Not Found">>}.

%% @doc Handle request events, like request completed, exception
%% thrown, client timeout, etc. Must return `ok'.
handle_event(_Event, _Data, _Args) ->
    ok.

Supervisor Childspec

To add elli to a supervisor you can use the following example and adapt it to your needs.

-module(fancyapi_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).

start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).

init([]) ->
    ElliOpts = [{callback, fancyapi_callback}, {port, 3000}],
    ElliSpec = {
        fancy_http,
        {elli, start_link, [ElliOpts]},
        permanent,
        5000,
        worker,
        [elli]},

    {ok, { {one_for_one, 5, 10}, [ElliSpec]} }.

Further Reading

For more information about the features and design philosophy of elli check out the overview.

License

Elli is licensed under The MIT License.

elli's People

Contributors

knutin avatar yurrriq avatar tsloughter avatar andreashasse avatar deadtrickster avatar chrisavl avatar mmzeeman avatar paulo-ferraz-oliveira avatar hukl avatar galdor avatar zambal avatar kaos avatar phuesler avatar sthadka avatar jeffgrunewald avatar vagabond avatar sg2342 avatar eproxus avatar zampino avatar cvik avatar evanmcc avatar lpil avatar mkrogemann avatar hungryblank avatar istr avatar sztheory avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.