Framework for building simple REST API endpoints


License
Apache-2.0

Documentation

Lightning

Lightning is an Elixir library for making simple REST API endpoints based on Plug

Hex version badge Docs

How to get started:

Create a new file (App.ex)

defmodule App do 
   use Lightning.HTTP
   import Lightning

 #Create a new route endpoint
 #Route: GET "/helloworld/"
 def route("GET", ["helloworld"], conn, res) do

    #Set additional response information (based on Plug responses)
    conn 
    |> res.put_resp_header("Hello", "World")
    |> res.put_resp_content_type("text/html")
    |> res.put_resp_cookie("abc", "def")
    |> res.put_status(200)

    #Send a text response with a statuscode of 200:
    text(conn, 200, "Hello world")
   end
end

Running the server

Start up a server using the iex command:

    iex -S mix
    iex> {:ok, _} = Lightning.start(5000, App, :dev)
    

Navigating to localhost:5000/helloworld will output text response:
Hello world

Example Code

code example