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
Ad

More Related Content

What's hot (20)

Apache solr liferay
Apache solr liferayApache solr liferay
Apache solr liferay
Binesh Gummadi
 
Xml parsers
Xml parsersXml parsers
Xml parsers
Manav Prasad
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Ot performance webinar
Ot performance webinarOt performance webinar
Ot performance webinar
Suite Solutions
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
Jussi Pohjolainen
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09
Elizabeth Smith
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
searchbox-com
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
Elizabeth Smith
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
Jim Bethancourt
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
Mark Harrison
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09
Elizabeth Smith
 
32.java input-output
32.java input-output32.java input-output
32.java input-output
santosh mishra
 
Io streams
Io streamsIo streams
Io streams
Elizabeth alexander
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
Alexandre Rafalovitch
 
Code generating beans in Java
Code generating beans in JavaCode generating beans in Java
Code generating beans in Java
Stephen Colebourne
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
Elizabeth Smith
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
Santosh Dhoundiyal
 
Query Parsing - Tips and Tricks
Query Parsing - Tips and TricksQuery Parsing - Tips and Tricks
Query Parsing - Tips and Tricks
Erik Hatcher
 
From content to search: speed-dating Apache Solr (ApacheCON 2018)
From content to search: speed-dating Apache Solr (ApacheCON 2018)From content to search: speed-dating Apache Solr (ApacheCON 2018)
From content to search: speed-dating Apache Solr (ApacheCON 2018)
Alexandre Rafalovitch
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
Elizabeth Smith
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09
Elizabeth Smith
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
searchbox-com
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
Elizabeth Smith
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09
Elizabeth Smith
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
Alexandre Rafalovitch
 
Query Parsing - Tips and Tricks
Query Parsing - Tips and TricksQuery Parsing - Tips and Tricks
Query Parsing - Tips and Tricks
Erik Hatcher
 
From content to search: speed-dating Apache Solr (ApacheCON 2018)
From content to search: speed-dating Apache Solr (ApacheCON 2018)From content to search: speed-dating Apache Solr (ApacheCON 2018)
From content to search: speed-dating Apache Solr (ApacheCON 2018)
Alexandre Rafalovitch
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
Elizabeth Smith
 

Viewers also liked (16)

Erlang web framework: Chicago boss
Erlang web framework: Chicago bossErlang web framework: Chicago boss
Erlang web framework: Chicago boss
Barcamp Saigon
 
Caching Strategies for an Erlang Based Web Stack
Caching Strategies for an Erlang Based Web StackCaching Strategies for an Erlang Based Web Stack
Caching Strategies for an Erlang Based Web Stack
enriquepazperez
 
learn you some erlang - chap 6 to chap7
learn you some erlang - chap 6 to chap7learn you some erlang - chap 6 to chap7
learn you some erlang - chap 6 to chap7
경미 김
 
learn you some erlang - chap0 to chap2
learn you some erlang - chap0 to chap2learn you some erlang - chap0 to chap2
learn you some erlang - chap0 to chap2
경미 김
 
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
GeeksLab Odessa
 
MPI, Erlang and the web
MPI, Erlang and the webMPI, Erlang and the web
MPI, Erlang and the web
Lenz Gschwendtner
 
Why erlang
Why erlangWhy erlang
Why erlang
Doug Goldie
 
Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버
Jaejin Yun
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
guest3933de
 
Design Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational DatabasesDesign Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational Databases
guestdfd1ec
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practice
litaocheng
 
learn you some erlang - chap13 to chap14
learn you some erlang - chap13 to chap14learn you some erlang - chap13 to chap14
learn you some erlang - chap13 to chap14
경미 김
 
Actors in erlang
Actors in erlangActors in erlang
Actors in erlang
Hyun Dong Lee
 
Barcamp2013
Barcamp2013Barcamp2013
Barcamp2013
Thai Cuong
 
Using OTP and gen_server Effectively
Using OTP and gen_server EffectivelyUsing OTP and gen_server Effectively
Using OTP and gen_server Effectively
Ken Pratt
 
NoSQL CGN: Riak (01/2012)
NoSQL CGN: Riak (01/2012)NoSQL CGN: Riak (01/2012)
NoSQL CGN: Riak (01/2012)
Sebastian Cohnen
 
Erlang web framework: Chicago boss
Erlang web framework: Chicago bossErlang web framework: Chicago boss
Erlang web framework: Chicago boss
Barcamp Saigon
 
Caching Strategies for an Erlang Based Web Stack
Caching Strategies for an Erlang Based Web StackCaching Strategies for an Erlang Based Web Stack
Caching Strategies for an Erlang Based Web Stack
enriquepazperez
 
learn you some erlang - chap 6 to chap7
learn you some erlang - chap 6 to chap7learn you some erlang - chap 6 to chap7
learn you some erlang - chap 6 to chap7
경미 김
 
learn you some erlang - chap0 to chap2
learn you some erlang - chap0 to chap2learn you some erlang - chap0 to chap2
learn you some erlang - chap0 to chap2
경미 김
 
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
WebCamp: Developer Day: N2O: The Most Powerful Erlang Web Framework - Максим ...
GeeksLab Odessa
 
Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버Erlang을 이용한 swap 서버
Erlang을 이용한 swap 서버
Jaejin Yun
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
guest3933de
 
Design Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational DatabasesDesign Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational Databases
guestdfd1ec
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practice
litaocheng
 
learn you some erlang - chap13 to chap14
learn you some erlang - chap13 to chap14learn you some erlang - chap13 to chap14
learn you some erlang - chap13 to chap14
경미 김
 
Using OTP and gen_server Effectively
Using OTP and gen_server EffectivelyUsing OTP and gen_server Effectively
Using OTP and gen_server Effectively
Ken Pratt
 
Ad

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

Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applications
amichoksi
 
CustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputsCustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputs
Suite Solutions
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
srinivasanjayakumar
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
vikram singh
 
Php
PhpPhp
Php
Tohid Kovadiya
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
Stephan Schmidt
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
BG Java EE Course
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
Pranav Sharma
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
Pranav Sharma
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
Stephan Schmidt
 
Struts2
Struts2Struts2
Struts2
Scott Stanlick
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
Metadata Extraction and Content Transformation
Metadata Extraction and Content TransformationMetadata Extraction and Content Transformation
Metadata Extraction and Content Transformation
Alfresco Software
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
5 xml parsing
5   xml parsing5   xml parsing
5 xml parsing
gauravashq
 
Spine.js
Spine.jsSpine.js
Spine.js
wearefractal
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applications
amichoksi
 
CustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputsCustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputs
Suite Solutions
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
Stephan Schmidt
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
Pranav Sharma
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
Pranav Sharma
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
Stephan Schmidt
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
Metadata Extraction and Content Transformation
Metadata Extraction and Content TransformationMetadata Extraction and Content Transformation
Metadata Extraction and Content Transformation
Alfresco Software
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
Ad

Recently uploaded (20)

Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 

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.