GithubHelp home page GithubHelp logo

xrzhao / leptus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sinasamavati/leptus

0.0 2.0 0.0 2.69 MB

Erlang REST framework that runs on top of cowboy

License: MIT License

Makefile 4.16% Emacs Lisp 0.32% Erlang 95.52%

leptus's Introduction

Leptus https://travis-ci.org/s1n4/leptus.png?branch=master

Leptus is an Erlang REST framework that runs on top of cowboy.

Leptus aims at simply creating RESTful APIs.

Requirements

Installation

Clone it and just run make

OR

If you want to use it as a dependency in your project add the following to your rebar configuration

{deps, [
        ...
        {leptus, ".*", {git, "git://github.com/s1n4/leptus.git", {branch, "master"}}}
       ]}.

NOTE: if you prefer jsx rather than jiffy the environment variable USE_JSX must be set to true when getting dependencies and/or compiling.

i.e.

USE_JSX=true make
# OR
USE_JSX=true rebar get-deps compile

Quick example

-module(hello).
-compile({parse_transform, leptus_pt}).

%% leptus callbacks
-export([init/3]).
-export([get/3]).
-export([terminate/4]).

init(_Route, _Req, State) ->
    {ok, State}.

get("/", _Req, State) ->
    {<<"Hello, leptus!">>, State};
get("/hi/:name", Req, State) ->
    Status = ok,
    Name = leptus_req:param(Req, name),
    Body = [{<<"say">>, <<"Hi">>}, {<<"to">>, Name}],
    {Status, {json, Body}, State}.

terminate(_Reason, _Route, _Req, _State) ->
    ok.
$ erl -pa ebin deps/*/ebin
1> c(hello).
2> leptus:start_listener(http, [{'_', [{hello, undefined_state}]}]).
Leptus started on http://127.0.0.1:8080
$ curl localhost:8080/hi/Leptus
{"say":"Hi","to":"Leptus"}

Features

  • Supports GET, PUT, POST and DELETE HTTP methods
  • Can respond in plain text, JSON or MessagePack
  • Supports basic authentication
  • Can be upgraded while it’s running (no stopping is required)
  • Supports HTTPS and SPDY
  • Provides a simple way for dealing with Cross-Origin Resource Sharing

Documentation

Check out the docs directory.

Support

License

MIT, see LICENSE file for more details.

leptus's People

Contributors

bitdeli-chef avatar hamidreza-s avatar marshall-lee avatar sinasamavati avatar srmerritt avatar

Watchers

 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.