SlideShare a Scribd company logo
Server-side web development Using  ErlangWeb Stefan Comanescu
A brief history of Erlang Initially developed by Joe Armstrong in 1986, as a proprietary language within Ericsson for usage in telephony applications
Named after the Danish mathematician Agner Krarup Erlang
First versions were running on a Prolog interpreter, a C emulator and a compiler were later written, for reasons concerning performance
In 1997 bit syntax and binaries were added (for protocol programming) and in the same year work started on OTP
Released as open source in 1998
SMP support was added in 2006
Why Erlang ? Concurrency Actor model (no threads, no locks, no shared memory, only asynchronous message passing) Fault Tolerance Process linking, supervising trees, distribution and event managers help in keeping the system going when processes crash. Distribution Abstracts the difference between local and distributed message passing
Runs on Yaws or Inets web server
MVC (Model-View-Controller) paradigm Model – data (stored in mnesia/dets tables) manipulation
Templates – XHTML files and templating engine
Controller – Erlang functions called on dispatching rules
Dispatcher – Request routing based on regexp
Request dictionary  Reusable components (“ecomponent”)
Caching system
Annotations
Directory structure For creating the directory tree of a new application, ./bin/add is executed which generates the directories:
config –dispatch.conf, errors.conf, projects.conf, server specific .conf
docroot –static files and folders (except html templates), e.g : js, css, img
lib –framework applications and applications created by the user
log –logs created while running in embedded mode and server specific log
pipes –OS pipes for cummunicating with the shell while in embeded mode
priv –project specific data (usually static html)
release –separated subdirectories for each release version
templates –all the template files templates/cache – cached files
Generator script (bin/generate.erl) Module responsible for generating the boilerplate code
General format: ./bin/generate.erl TYPE -argument_name -argument_value
Generating a controller: ./bin/generate.erl controller --app app_name --name name_of_the_generated_model --functions (fun1, fun2)
./bin/generate.erl model --app app_name --name name_of_the_generated_model --hrl name_of_the_header_file  Generates a file named wtype_name where 'name' is the given arg
Generates basic CRUD functionality for the given header
Dispatcher Dispatching types Static dispatching: serving static content, like xml pages, media or javascript. The controller is not accessed. The server first searches for the file in the “templates” dir, afterward in the “docroot” dir. For faster retrieval of static content, they should be placed in the docroot dir and enoent should be placed instead of File  {static, Regexp, File} | {static, Regexp, enoent} Dynamic dispatching: the controller will handle the URL requests allowing specific content to be created or retrieved on demand {dynamic, Regexp, {Module, Function}}  Alias dispatching: if the URL matches the Regexp, the rule of NewURL will be triggered {alias, Regexp, NewURL} Delegates: passing the URL to another dispatch config file, only helps in structuring the application {dynamic, delegate, Regexp, File}
Dispatcher evaluation order Docroot content is served (files that point to 'enoent')
Dynamic entries are matched with their URLs

More Related Content

PDF
Open Source RAD with OpenERP 7.0
PPT
30 5 Database Jdbc
PPTX
jstl ( jsp standard tag library )
PPT
Jstl Guide
PDF
JSP Standard Tag Library
PPT
Introduction To Ant
PDF
Streams in Java 8
PDF
Productive Programming in Java 8 - with Lambdas and Streams
Open Source RAD with OpenERP 7.0
30 5 Database Jdbc
jstl ( jsp standard tag library )
Jstl Guide
JSP Standard Tag Library
Introduction To Ant
Streams in Java 8
Productive Programming in Java 8 - with Lambdas and Streams

What's hot (20)

PDF
Apache solr liferay
PPT
Xml parsers
PPT
Chapter 12 - File Input and Output
PPTX
Ot performance webinar
PDF
PPTX
Spl to the Rescue - Zendcon 09
PPTX
Tutorial on developing a Solr search component plugin
PDF
Writing and using php streams and sockets tek11
PPTX
Java 8 Feature Preview
PDF
Java 8 by example!
PDF
SPL to the Rescue - Tek 09
PDF
32.java input-output
PPTX
PDF
Solr Troubleshooting - TreeMap approach
PDF
Code generating beans in Java
PDF
Spl in the wild
DOC
Servlet basics
PDF
Query Parsing - Tips and Tricks
PDF
From content to search: speed-dating Apache Solr (ApacheCON 2018)
PPTX
Streams, sockets and filters oh my!
Apache solr liferay
Xml parsers
Chapter 12 - File Input and Output
Ot performance webinar
Spl to the Rescue - Zendcon 09
Tutorial on developing a Solr search component plugin
Writing and using php streams and sockets tek11
Java 8 Feature Preview
Java 8 by example!
SPL to the Rescue - Tek 09
32.java input-output
Solr Troubleshooting - TreeMap approach
Code generating beans in Java
Spl in the wild
Servlet basics
Query Parsing - Tips and Tricks
From content to search: speed-dating Apache Solr (ApacheCON 2018)
Streams, sockets and filters oh my!
Ad

Viewers also liked (16)

PDF
Erlang web framework: Chicago boss
PDF
Caching Strategies for an Erlang Based Web Stack
PDF
learn you some erlang - chap 6 to chap7
PDF
learn you some erlang - chap0 to chap2
PDF
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
PDF
MPI, Erlang and the web
PPTX
Why erlang
PPT
Erlang을 이용한 swap 서버
PPS
Erlang plus BDB: Disrupting the Conventional Web Wisdom
PDF
Design Patterns for Distributed Non-Relational Databases
PDF
Erlang Practice
PDF
learn you some erlang - chap13 to chap14
PPTX
Actors in erlang
PDF
Barcamp2013
PDF
Using OTP and gen_server Effectively
PDF
NoSQL CGN: Riak (01/2012)
Erlang web framework: Chicago boss
Caching Strategies for an Erlang Based Web Stack
learn you some erlang - chap 6 to chap7
learn you some erlang - chap0 to chap2
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
MPI, Erlang and the web
Why erlang
Erlang을 이용한 swap 서버
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Design Patterns for Distributed Non-Relational Databases
Erlang Practice
learn you some erlang - chap13 to chap14
Actors in erlang
Barcamp2013
Using OTP and gen_server Effectively
NoSQL CGN: Riak (01/2012)
Ad

Similar to Developing web apps using Erlang-Web (20)

ODP
Practical catalyst
PPT
Introducing Struts 2
PPT
Internet Technology and its Applications
PPT
CustomizingStyleSheetsForHTMLOutputs
PPT
Java XML Parsing
PPT
Sax Dom Tutorial
PPT
XML Transformations With PHP
PPT
Processing XML with Java
PPT
course slides -- powerpoint
PPTX
Using SP Metal for faster share point development
PPTX
Using SPMetal for faster SharePoint development
PPT
Inroduction to XSLT with PHP4
PPT
ODP
Bring the fun back to java
PPTX
Metadata Extraction and Content Transformation
PPT
Laurens Van Den Oever Xopus Presentation
PPT
r,rstats,r language,r packages
PPT
5 xml parsing
PPTX
Spine.js
Practical catalyst
Introducing Struts 2
Internet Technology and its Applications
CustomizingStyleSheetsForHTMLOutputs
Java XML Parsing
Sax Dom Tutorial
XML Transformations With PHP
Processing XML with Java
course slides -- powerpoint
Using SP Metal for faster share point development
Using SPMetal for faster SharePoint development
Inroduction to XSLT with PHP4
Bring the fun back to java
Metadata Extraction and Content Transformation
Laurens Van Den Oever Xopus Presentation
r,rstats,r language,r packages
5 xml parsing
Spine.js

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Monthly Chronicles - July 2025
Dropbox Q2 2025 Financial Results & Investor Presentation

Developing web apps using Erlang-Web

  • 1. Server-side web development Using ErlangWeb Stefan Comanescu
  • 2. A brief history of Erlang Initially developed by Joe Armstrong in 1986, as a proprietary language within Ericsson for usage in telephony applications
  • 3. Named after the Danish mathematician Agner Krarup Erlang
  • 4. First versions were running on a Prolog interpreter, a C emulator and a compiler were later written, for reasons concerning performance
  • 5. In 1997 bit syntax and binaries were added (for protocol programming) and in the same year work started on OTP
  • 6. Released as open source in 1998
  • 7. SMP support was added in 2006
  • 8. Why Erlang ? Concurrency Actor model (no threads, no locks, no shared memory, only asynchronous message passing) Fault Tolerance Process linking, supervising trees, distribution and event managers help in keeping the system going when processes crash. Distribution Abstracts the difference between local and distributed message passing
  • 9. Runs on Yaws or Inets web server
  • 10. MVC (Model-View-Controller) paradigm Model – data (stored in mnesia/dets tables) manipulation
  • 11. Templates – XHTML files and templating engine
  • 12. Controller – Erlang functions called on dispatching rules
  • 13. Dispatcher – Request routing based on regexp
  • 14. Request dictionary Reusable components (“ecomponent”)
  • 17. Directory structure For creating the directory tree of a new application, ./bin/add is executed which generates the directories:
  • 18. config –dispatch.conf, errors.conf, projects.conf, server specific .conf
  • 19. docroot –static files and folders (except html templates), e.g : js, css, img
  • 20. lib –framework applications and applications created by the user
  • 21. log –logs created while running in embedded mode and server specific log
  • 22. pipes –OS pipes for cummunicating with the shell while in embeded mode
  • 23. priv –project specific data (usually static html)
  • 24. release –separated subdirectories for each release version
  • 25. templates –all the template files templates/cache – cached files
  • 26. Generator script (bin/generate.erl) Module responsible for generating the boilerplate code
  • 27. General format: ./bin/generate.erl TYPE -argument_name -argument_value
  • 28. Generating a controller: ./bin/generate.erl controller --app app_name --name name_of_the_generated_model --functions (fun1, fun2)
  • 29. ./bin/generate.erl model --app app_name --name name_of_the_generated_model --hrl name_of_the_header_file Generates a file named wtype_name where 'name' is the given arg
  • 30. Generates basic CRUD functionality for the given header
  • 31. Dispatcher Dispatching types Static dispatching: serving static content, like xml pages, media or javascript. The controller is not accessed. The server first searches for the file in the “templates” dir, afterward in the “docroot” dir. For faster retrieval of static content, they should be placed in the docroot dir and enoent should be placed instead of File {static, Regexp, File} | {static, Regexp, enoent} Dynamic dispatching: the controller will handle the URL requests allowing specific content to be created or retrieved on demand {dynamic, Regexp, {Module, Function}} Alias dispatching: if the URL matches the Regexp, the rule of NewURL will be triggered {alias, Regexp, NewURL} Delegates: passing the URL to another dispatch config file, only helps in structuring the application {dynamic, delegate, Regexp, File}
  • 32. Dispatcher evaluation order Docroot content is served (files that point to 'enoent')
  • 33. Dynamic entries are matched with their URLs
  • 34. Static routes are matched
  • 35. If no patterns are matched, a 404 error page is displayed
  • 36. Request dictionary Temporary storage – created for each HTTP request, lives as long as the request lives
  • 37. Provides an easy to use API for setting and getting values from the dictionary
  • 38. Used for retrieving GET/POST request data from the query string and also used by the expanding templates
  • 42. Request dictionary Sample browser request {<0.3110.0>,[ {&quot;get&quot;,[]}, {&quot;post&quot;,[ {&quot;action_type&quot;,&quot;add&quot;},{&quot;id&quot;,[]},{&quot;type&quot;,&quot;user&quot;},{&quot;user_password&quot;,&quot;nuitizic&quot;}, {&quot;user_phone&quot;,&quot;07273447823&quot;},{&quot;user_cnp&quot;,&quot;1901231231723&quot;}, {&quot;user_lastname&quot;,&quot;alex&quot;},{&quot;user_firstname&quot;,&quot;popescu&quot;} ] }, {&quot;__https&quot;,false}, {&quot;__cookies&quot;,[{&quot;eptic_cookie&quot;,&quot;nonode@nohost-7985065742948673537&quot;}]}, {&quot;session&quot;,[{&quot;user_id&quot;,&quot;1111111111111&quot;}, {&quot;groups&quot;,[&quot;admin&quot;]}]}, {&quot;__path&quot;,&quot;admin/add&quot;}, {&quot;__cookie_key&quot;,&quot;nonode@nohost-7985065742948673537&quot;},{&quot;__ip&quot;,{127,0,0,1}}, {&quot;__controller&quot;,controller} ] }
  • 43. Controller Responsible for handling the user's requests
  • 44. Has the arity 1, getting a proplist (list of key-value pairs)
  • 45. Handles user input, model manipulation, etc.
  • 46. Must return a tuple, which tells the template what to do: {redirect, URL} | {content,html,Data} | {content,text,Data} | {json,Data} | {template,Template} | {error,Code} | {headers, Headers, RetVal} where : Headers is a list of headers, of the form {cookie, CookieName, CookieValue, CookiePath, CookieExpDate}
  • 47. Retval is one of the previous touples
  • 48. Templating Engine The view is represented by a regular XHTML file with a few namespaces defined.
  • 49. The most commonly used namespace, wpart, is always expanded by the framework . When the parser meets <wpart:lookup … /> for example, it will call the function wpart_lookup:handle_call/1, with the whole xmerl parsed tag as an argument.
  • 50. Templating Engine Wpart tags wpart:choose provides “if” functionality; it contains the tags: <wpart:when test=”...”> … </wpart:when>
  • 51. <wpart:otherwise> Something else </wpart:otherwise>
  • 52. The test is an expression of the form test=”1 + 1 eq 2”, where the operators can be: eq, neq, lt, le, gt, ge (for =:=, =/=, <, >, =<, >=)
  • 53. Templating Engine Wpart tags wpart:list provides “for” functionality; it contain the attributes: select, specified what part of the list we want, attributes: map – renders every element in the list
  • 54. head – renders only the first element
  • 55. tail – renders the last element of the list
  • 56. filter – has an attribute named “pred” for filtering the list
  • 57. find – the first element of the list where “pred” is evaled to true
  • 58. sort – sorts according to the “pred” attribute as, every element of the list from inside the wpart:list will be known as the value of this attribute
  • 59. Templating Engine Wpart tags list, specifies the list from the request dictionary that we want to traverse
  • 60. pred, predicate used for some of the select tags, it's optional
  • 61. e.g. : <wpart:list select=”map” list=”students” as=”student”> <span class=”name”><wpart:lookup value=”student:name”/></span> <span class=”group”><wpart:lookup value=”student:group”/></span> </wpart:list>
  • 62. Templating Engine Wpart tags wpart:lookup provides access to a value from inside the request dictionary, it contains the attributes: key, the key from the dictionary that we are looking for
  • 64. type, can have the values “text” (default) or “html”, setting “html” turns off html-escaping and can be dangerous
  • 65. e.g : <wpart:lookup key=”name”/> <wpart:lookup key=”student:name”/>
  • 66. Templating Engine (wtpl) Tool for faster building of html pages, by expanding or replacing content from other template files
  • 67. Allows building of websites from small chunks of html
  • 68. It helps with : Code re-usage
  • 69. Not writing the same thing multiple times
  • 70. Updating the common part of the pages only one time
  • 71. Templating Engine (wtpl) Wtpl tags <wtpl:include name=Name /> - the location where the wtpl:content with the corresponding name will be placed
  • 72. <wtpl:parent path=Path /> - specifies which template will be filled with the content provided by the wtpl:content content
  • 73. <wtpl:content name=Name/> - content that will fill the wtpl:include tag which has the same name as the tag 'name' attribute, in the file specified by wtpl:parent
  • 74. Templating Engine wpart_gen Enables building of HTML code directly from within Erlang modules.
  • 75. wpart_gen:load_tpl(Namespace, Name, Path) – loads the html snippet specified by Path, and saves it in the memory under the key {Namespace,Name}
  • 76. Tpl = wpart_gen:tpl_get(Namespace,Name) – gets the snippet from memory
  • 77. wpart_gen:build_html(Tpl,Values) – builds the template file with the values from the list Values
  • 78. Templating Engine wpart_gen – Template Format Anonymous slots: <!-- HTMLCode --> <% slot %> <!-- HTMLCode --> Named slots: <!-- HTMLCode --> <% name_of_the_slot %> <!-- HTMLCode -->
  • 79. Templating Engine wpart_gen – Passed Values Anonymous slots: [Value | … ] All fields must be filled. Named slots: [{ “slot_name”, Value} | … ] The unfilled slots will remain empty.
  • 80. Controlling cache persistent – data cached this way is not removed until the server is restarted or the cache is invalidated
  • 81. timeout – every T minutes the cache is traversed and expired content is removed, each URL can have a different timeout.
  • 83. Controlling cache The caching configuration is made directly from the dispatch configuration file. E.g. : {dynamic, “^/index/?$”,{main,home},[{cache,persistent}]}.
  • 87. Controlling cache For controlling cache based on aspects other than URL, the tuple {is_cachable_mod, my_mod} should be placed in the configuration(config/project.conf) file.
  • 88. Before processing any request, the function my_mod:is_cachable() will be called
  • 89. The function is_cachable() should return true if the request should be cached under the URL key
  • 90. {true,NewId} , if the request should be cached under NewId
  • 91. false , if we don't want to check the cache
  • 92. Annotations Available since version 1.3
  • 93. Allows separation of the target function from different types of functions, non-domain specific wrappers.
  • 94. e.g.: before making a post to a blog you should be logged in and your message should be checked for “bad words” maybe; after posting the message the cache should be invalidated and your post-count could be modified.
  • 95. Usual dataflow mechanisms can be used but it could make the code harder to read and repetitive.
  • 96. Annotations Controller Syntax % keeps the stored macros -include_lib(“blog/include/utils_annotations.hrl”). % before posting ?AUTHENTICATE([“administrator”]). ?CHECK(blog_post). % after posting ?INVALIDATE(posts). ?UPDATE(user). post(_Args) -> ...
  • 97. Annotations Annotation Module Syntax ?BEFORE. %% ?AFTER. annotation_name(AnnotationArg, TargetModule, TargetFunction, TargetFunctionArgs | TargetFunctionResult) -> Result Result :: {proceed, NewFunctionArgs | NewResult} | {skip, NewResult} | {error, {ErrorMod, ErrorFun, ErrorArgs}}
  • 98. Annotations Annotation Module Example ?AFTER. check (blog_post, _Mod, _Fun, _Args) -> case is_bad(wpart:fget(“post:msg”)) of true-> {skip, {redirect, “http://correctiveschool.org”}}; _-> {proceed, _Args} end.
  • 99. e_components e_components is a mechanism for extending the capabilities of the framework
  • 100. Erlang-Web comes with e_components for authentication, mnesia backup and for generating rss feeds
  • 101. To search for an e_component we can run ./bin/e_component search component_name, command that will list all available components matching the name and their description
  • 102. To install an e_component we run ./bin/e_component install component_name, the e_component is now copied in the lib folder of our application. ./bin/compile is now required, in order to compile the component's source files.
  • 103. e_components One more thing is required in order to use the component in our project: inserting a new tuple in the configuration file: {ecomponents, [{e_auth, []}, {e_auth_dets, []} ]}. After restarting the server we can verify that the components are running, by executing the function that lists all running applications : application:which_applications()
  • 104. e_components e_components is a mechanism for extending the capabilities of the framework
  • 105. Erlang-Web comes with e_components for authentication, mnesia backup and for generating rss feeds
  • 106. To search for an e_component we can run ./bin/e_component search component_name, command that will list all available components matching the name and their description
  • 107. To install an e_component we run ./bin/e_component install component_name, the e_component is now copied in the lib folder of our application. ./bin/compile is now required, in order to compile the component's source files.
  • 108.  
  • 109.