Coder Social home page Coder Social logo

erlskeletor_cowboy's Introduction

erlskeletor

Erlang erlskeletor with three http endpoints created with cowboy, erlang.mk and relx.

#Run it! To download dependencies and compile everything:

make

To run the erlang shell and launch everything:

make shell

The root handler answers with an html that will create an EventSource to receive server sent events. Open your browser and go to /. The messages will get appended to the DOM.

$ curl -X GET "http://localhost:8080/" 
<html>
<head>
  <meta charset="utf-8">
<body>
  <script>
    var source = new EventSource("http://localhost:8080/events")
    source.onmessage = function(message) {
      console.log("got a new message:", message.data);
      var p = document.createElement("p")
      var t =document.createTextNode(message.data);
      p.appendChild(t);
      document.body.appendChild(p);
    }
  </script>

</body>
</html>

You can fetch the messages sent by the server if you send a GET to /events

$ curl -X GET "http://localhost:8080/events" 
id: date
data: 2014-6-2T21:34:56Z

id: date
data: 2014-6-2T21:34:57Z

^Cfish: Job 1, “curl -X GET "http://localhost:8080/events" ” terminated by signal SIGINT (Quit request from job control (^C))

And at last you can GET the /foobar endpoint to receive a foo bar in JSON sauce

$ curl -X GET "http://localhost:8080/foobar" 
{"foo":"bar"}

The changes you do to the source code are autocompiled, purged and loaded when while you are developing and using make shell thanks to sync. The -s sync flag in this line from the Makefile is responsible for starting sync. Remove it if you don't like it.

At the erlang shell you will see the following messages when sync recompiles your code:

([email protected])2> 18:55:07.143 [info] /Users/pyotrgalois/projects/erlskeletor/src/erlskeletor_root_handler.erl:0: Recompiled.
18:55:07.150 [info] erlskeletor_root_handler: Reloaded! (Beam changed.)

To execute the release recompile with make and call _rel/bin/erlskeletor console:

make
_rel/bin/erlskeletor console 

#Why?

#Propaganada

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.