SlideShare a Scribd company logo
A RESTful interface for Erlang
code
using Webmachine
Copyright 2014 Carl Wright
RESTful interface
• Exposes your app as resources on the
Web.
• Resources respond to 6 HTTP methods:
GET, HEAD, POST, PUT, DELETE and
OPTIONS
HTTP: interface to your erlang app
• Start with an erlang
app
• add webmachine
code
• Write the dispatch
table & web app start
• Write the resource
code indicated by the
dispatch table
Erlang
app
Webmachine
HTTP:
A specific application
Webui holds the
code to respond
to URIs
Webmachine provides an
HTTP server to handle
URI requests on a specific
channel.
Adding webmachine
• Go to
https://github.com/basho/webmachine/wiki
• To see the documentation and to fork a
copy of webmachine
• Add it to your erlang application.
The others apps
• To run webmachine, you need the
following apps:
– mochiweb
• http interaction support library
– crypto
• Cryptographic functions to support secure web
– inets
• Base webservices (ftp, tftp, http, https, etc.)
Adding to your app definition
• You have a “.rel” to
define your
application release.
Yes, you need mochiweb, too.
Mochiweb is installed along
webmachine and your “webui”
folder.
Crypto and inets are in the
standard erlang libraries.
You just include them in
Your application definition.
Release configuration
• Add “webmachine” to your release
configuration files for “relx” or “rebar”.
• These are the most common release
managers for erlang systems.
Inside your web UI
• OTP folder structure
• ebin holds .app file
and compiled binaries
• priv holds the
dispatch table.
• src holds the
application source
code.
Webui.app (in ebin folder)
The src folder
Who does what?
webui_app
webui_sup
webmachine
webui_resource.erl
webui_resource_status.erl
dispatch
table
A simple dispatch table
1. http://host/device/status/7348272000
2. http://host {anything else}
Dispatch pattern
{ <pattern>, <resource-mod>, <init-params>}
i.e.
{[“a”], module_a, []}.
matches http://host/a & calls module_a
{[“a”, varname], module_a, []}.
match http://host/a/Carl & calls module_a
with “varname” = “Carl”
Left side pattern
• Is a list of any atom, string or star
• Breaks the URL on slashes
• Strings must match the URL contents
• Atoms associate with the value so that you
retrieve their value
• Star is “*” and must be the last in the list
when present.
A CRUD dispatch
• % Accounts
• {["account","add"], webui_resource_account,
[add, [{'POST', <<"accounts">>}]]},
• {["account","delete",id], webui_resource_account,
[delete, [{'POST', <<"accounts">>}]]},
• {["account","edit",id], webui_resource_account,
[edit, [{'POST', <<"accounts">>}]]},
• {["accounts"], webui_resource_account,
[account_many,[{'GET', <<"accounts">>}]]},
• {["json","accounts"], webui_resource_account,
[accounts, [{'GET', <<"accounts">>}]]},
A real resource function
How does a resource function wire
up to the web?
• There is a mapping between 30+ functions
that you can put in a resource module.
• They map to states in the HTTP state
machine that webmachine implements.
Resource functions
• resource_exists
• service_available
• allowed_methods
• content_types_provid
ed
• etcetera
• These functions all
have default values
when absent.
• You only write
functions when you
needs something
more.
content_types_provided
• This function defines the types of content
that the module can provide.
• It defaults to [{“text/html”,to_html}] .
• to_html is function name that creates the
results.
• You might want this to return
[{“text/html”,to_html}, {“json”,to_json}]
A real resource function
Actual results
Questions?

More Related Content

PPTX
Salesforce ANT migration
PPTX
API Development with Laravel
PPTX
A introduction to Laravel framework
PPTX
Introduction to laravel framework
PPTX
10 Laravel packages everyone should know
PDF
Laravel 5 Annotations: RESTful API routing
PDF
เกี่ยวกับ Apache solr 4.0
Salesforce ANT migration
API Development with Laravel
A introduction to Laravel framework
Introduction to laravel framework
10 Laravel packages everyone should know
Laravel 5 Annotations: RESTful API routing
เกี่ยวกับ Apache solr 4.0

What's hot (20)

PPTX
Intro to Laravel
PDF
Getting to know Laravel 5
PDF
DevJam 2019 - Building an ALEC Time Engine
PDF
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
PDF
ACL in CodeIgniter
PPTX
Laravel 5
PPTX
Introduction to Laravel Framework (5.2)
PPTX
REST API Best Practices & Implementing in Codeigniter
PPTX
Raml part 2
KEY
CakePHP REST Plugin
PPTX
Raml part 1
PPT
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
PDF
Try using Aeromock by Marverick, Inc.
PPTX
Laravel Tutorial PPT
PDF
All the Laravel things: up and running to making $$
PDF
MidwestPHP 2016 - Adventures in Laravel 5
PPTX
Laravel overview
PDF
All Aboard for Laravel 5.1
PDF
What's New In Laravel 5
PDF
One does not simply "Upgrade to Rails 3"
Intro to Laravel
Getting to know Laravel 5
DevJam 2019 - Building an ALEC Time Engine
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
ACL in CodeIgniter
Laravel 5
Introduction to Laravel Framework (5.2)
REST API Best Practices & Implementing in Codeigniter
Raml part 2
CakePHP REST Plugin
Raml part 1
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Try using Aeromock by Marverick, Inc.
Laravel Tutorial PPT
All the Laravel things: up and running to making $$
MidwestPHP 2016 - Adventures in Laravel 5
Laravel overview
All Aboard for Laravel 5.1
What's New In Laravel 5
One does not simply "Upgrade to Rails 3"
Ad

Viewers also liked (19)

PPTX
Factores de riesgo
PDF
Trc Finance Unbundled
PPTX
"My Business Doesnt Need A Social Media Strategy"
PPT
Graffiti-Montaje
PDF
PDF
Trabajo de electricidad
PPTX
Realida Aumentada
PDF
Demos_Tulevaisuusvaliokunta_030409
PPT
Arquitectura
PDF
Manejo de conectores
PPTX
სახის ტრანსპლანტაცია
PPTX
P440 PPT 2014 excerpts
DOCX
Taller.1
PPSX
Motivasi caleg
PDF
Park West Gallery Christmas Fine Art (2010)
PDF
MLG Warner Brothers_300_012414
PPTX
Projeto sustentável
PPT
Slideshare
Factores de riesgo
Trc Finance Unbundled
"My Business Doesnt Need A Social Media Strategy"
Graffiti-Montaje
Trabajo de electricidad
Realida Aumentada
Demos_Tulevaisuusvaliokunta_030409
Arquitectura
Manejo de conectores
სახის ტრანსპლანტაცია
P440 PPT 2014 excerpts
Taller.1
Motivasi caleg
Park West Gallery Christmas Fine Art (2010)
MLG Warner Brothers_300_012414
Projeto sustentável
Slideshare
Ad

Similar to A RESTful Interface for Erlang Code using Webmachine (20)

KEY
Polyglot parallelism
PDF
WebApp #3 : API
PDF
Creating Restful Web Services with restish
PDF
Web Clients for Ruby and What they should be in the future
PDF
REST APIS web development for backend familiarity
PDF
A Practical Guide To Hypermedia APIs - Philly.rb
PDF
Ruby MVC from scratch with Rack
PDF
REST API Basics
PPTX
Will be an introduction to
PPTX
rest-api-basics.pptx
PPTX
RESTful Web Services
PPTX
Rest with Java EE 6 , Security , Backbone.js
PPTX
PPTX
A Deep Dive into RESTful API Design Part 2
PDF
Functional Web Apps with WebMachine Framework - Mikhail Bortnyk
PDF
Functional Web Apps with WebMachine Framework
PPTX
Tutorial_Rest_API_For_Beginners_125.pptx
PPTX
Lightweight Approach to Building Web APIs with .NET
PPTX
Design Summit - RESTful API Overview - John Hardy
PPTX
rest-api-basics.pptx
Polyglot parallelism
WebApp #3 : API
Creating Restful Web Services with restish
Web Clients for Ruby and What they should be in the future
REST APIS web development for backend familiarity
A Practical Guide To Hypermedia APIs - Philly.rb
Ruby MVC from scratch with Rack
REST API Basics
Will be an introduction to
rest-api-basics.pptx
RESTful Web Services
Rest with Java EE 6 , Security , Backbone.js
A Deep Dive into RESTful API Design Part 2
Functional Web Apps with WebMachine Framework - Mikhail Bortnyk
Functional Web Apps with WebMachine Framework
Tutorial_Rest_API_For_Beginners_125.pptx
Lightweight Approach to Building Web APIs with .NET
Design Summit - RESTful API Overview - John Hardy
rest-api-basics.pptx

More from OnorioCatenacci (6)

ODP
Basics Of Elixir and Phoenix
ODP
Gentle Introduction To Funcitonal Programming - Detroit.Code
PPT
Building An Elixir Package
PPTX
Alternate languages for the CLR
PPTX
A Sip Of Elixir
PDF
Shell scripting with f
Basics Of Elixir and Phoenix
Gentle Introduction To Funcitonal Programming - Detroit.Code
Building An Elixir Package
Alternate languages for the CLR
A Sip Of Elixir
Shell scripting with f

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
A Presentation on Artificial Intelligence
PPTX
Big Data Technologies - Introduction.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Assigned Numbers - 2025 - Bluetooth® Document
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Programs and apps: productivity, graphics, security and other tools
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
A Presentation on Artificial Intelligence
Big Data Technologies - Introduction.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
gpt5_lecture_notes_comprehensive_20250812015547.pdf

A RESTful Interface for Erlang Code using Webmachine

  • 1. A RESTful interface for Erlang code using Webmachine Copyright 2014 Carl Wright
  • 2. RESTful interface • Exposes your app as resources on the Web. • Resources respond to 6 HTTP methods: GET, HEAD, POST, PUT, DELETE and OPTIONS
  • 3. HTTP: interface to your erlang app • Start with an erlang app • add webmachine code • Write the dispatch table & web app start • Write the resource code indicated by the dispatch table Erlang app Webmachine HTTP:
  • 4. A specific application Webui holds the code to respond to URIs Webmachine provides an HTTP server to handle URI requests on a specific channel.
  • 5. Adding webmachine • Go to https://github.com/basho/webmachine/wiki • To see the documentation and to fork a copy of webmachine • Add it to your erlang application.
  • 6. The others apps • To run webmachine, you need the following apps: – mochiweb • http interaction support library – crypto • Cryptographic functions to support secure web – inets • Base webservices (ftp, tftp, http, https, etc.)
  • 7. Adding to your app definition • You have a “.rel” to define your application release.
  • 8. Yes, you need mochiweb, too. Mochiweb is installed along webmachine and your “webui” folder. Crypto and inets are in the standard erlang libraries. You just include them in Your application definition.
  • 9. Release configuration • Add “webmachine” to your release configuration files for “relx” or “rebar”. • These are the most common release managers for erlang systems.
  • 10. Inside your web UI • OTP folder structure • ebin holds .app file and compiled binaries • priv holds the dispatch table. • src holds the application source code.
  • 14. A simple dispatch table 1. http://host/device/status/7348272000 2. http://host {anything else}
  • 15. Dispatch pattern { <pattern>, <resource-mod>, <init-params>} i.e. {[“a”], module_a, []}. matches http://host/a & calls module_a {[“a”, varname], module_a, []}. match http://host/a/Carl & calls module_a with “varname” = “Carl”
  • 16. Left side pattern • Is a list of any atom, string or star • Breaks the URL on slashes • Strings must match the URL contents • Atoms associate with the value so that you retrieve their value • Star is “*” and must be the last in the list when present.
  • 17. A CRUD dispatch • % Accounts • {["account","add"], webui_resource_account, [add, [{'POST', <<"accounts">>}]]}, • {["account","delete",id], webui_resource_account, [delete, [{'POST', <<"accounts">>}]]}, • {["account","edit",id], webui_resource_account, [edit, [{'POST', <<"accounts">>}]]}, • {["accounts"], webui_resource_account, [account_many,[{'GET', <<"accounts">>}]]}, • {["json","accounts"], webui_resource_account, [accounts, [{'GET', <<"accounts">>}]]},
  • 18. A real resource function
  • 19. How does a resource function wire up to the web? • There is a mapping between 30+ functions that you can put in a resource module. • They map to states in the HTTP state machine that webmachine implements.
  • 20. Resource functions • resource_exists • service_available • allowed_methods • content_types_provid ed • etcetera • These functions all have default values when absent. • You only write functions when you needs something more.
  • 21. content_types_provided • This function defines the types of content that the module can provide. • It defaults to [{“text/html”,to_html}] . • to_html is function name that creates the results. • You might want this to return [{“text/html”,to_html}, {“json”,to_json}]
  • 22. A real resource function