Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Webmachine
Search
Jade Allen
October 16, 2013
Technology
0
120
Introduction to Webmachine
Webmachine is a toolkit to build REST APIs implemented in Erlang.
Jade Allen
October 16, 2013
Tweet
Share
More Decks by Jade Allen
See All by Jade Allen
All About Regular Expressions
jadeallenx
1
250
Hexes, Charms and Spells
jadeallenx
0
150
3 > 2
jadeallenx
0
960
Idiomatic Erlang
jadeallenx
0
150
The Sharp Edges of Leaky Abstractions
jadeallenx
0
97
Sagas: Distributed Transactions Without Locks
jadeallenx
0
560
Before Unix: Early History of Time-Sharing
jadeallenx
0
210
Functional Programming Made Me a Better Perl Developer
jadeallenx
1
350
Assigning Meanings to Programs
jadeallenx
0
210
Other Decks in Technology
See All in Technology
クラウド食堂とは?
hiyanger
0
120
1行のコードから社会課題の解決へ: EMの探究、事業・技術・組織を紡ぐ実践知 / EM Conf 2025
9ma3r
11
3.9k
Fraxinus00tw assembly manual
fukumay
0
110
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
300
技術スタックだけじゃない、業務ドメイン知識のオンボーディングも同じくらいの量が必要な話
niftycorp
PRO
0
110
Apache Iceberg Case Study in LY Corporation
lycorptech_jp
PRO
0
330
手を動かしてレベルアップしよう!
maruto
0
220
JavaにおけるNull非許容性
skrb
2
2.6k
IAMのマニアックな話2025
nrinetcom
PRO
4
820
AIエージェント入門
minorun365
PRO
31
18k
NFV基盤のOpenStack更新 ~9世代バージョンアップへの挑戦~
vtj
0
360
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
17
45k
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Being A Developer After 40
akosma
89
590k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Thoughts on Productivity
jonyablonski
69
4.5k
How to Ace a Technical Interview
jacobian
276
23k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Statistics for Hackers
jakevdp
797
220k
Rails Girls Zürich Keynote
gr2m
94
13k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.3k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
A designer walks into a library…
pauljervisheath
205
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Transcript
Introduction to Webmachine! ! ! Mark Allen!
[email protected]
! @bytemeorg! http://byte-me.org!
https://github.com/mrallen1!
HTTP is complicated!
None
Abstraction!
Toolkit!
A gentle introduction! to Erlang!
Sincerely flattered!
dj-webmachine! (python)!
webmachine.rb! (ruby)!
webmachine.js! (node)!
liberator! (clojure)!
scalamachine! (scala)!
Framework!
Framework!
None
Hello World! Resource!
-module(hello_world_resource). -export([init/1, to_html/2]). -include_lib("webmachine/include/webmachine.hrl"). init([]) -> {ok, "Hello, world"}. to_html(Req,
State) -> {io_lib:format("<html><head><title>~s</title></ head><body>~s</body></html>", [State, State]), Req, State}.
-module(hello_world_resource). -export([init/1, to_html/2]). -include_lib("webmachine/include/webmachine.hrl"). init([]) -> {ok, "Hello, world"}. to_html(Req,
State) -> {io_lib:format("<html><head><title>~s</title></ head><body>~s</body></html>", [State, State]), Req, State}.
-module(hello_world_resource). -export([init/1, to_html/2]). -include_lib("webmachine/include/webmachine.hrl"). init([]) -> {ok, "Hello, world"}. to_html(Req,
State) -> {io_lib:format("<html><head><title>~s</title></ head><body>~s</body></html>", [State, State]), Req, State}.
Conditional GET!
-module(hello_world_resource). -export([init/1, to_html/2, generate_etag/2]). -include_lib("webmachine/include/webmachine.hrl"). init([]) -> {ok, "Hello, world"}.
to_html(Req, State) -> {io_lib:format("<html><head><title>~s</title></ head><body>~s</body></html>", [State, State]), Req, State}. generate_etag(Req, State) -> {mochihex:to_hex(crypto:md5(State)), Req, State}.
Encoding Support!
-module(hello_world_resource). -export([init/1, to_html/2, generate_etag/2]). -export([encodings_provided/2]). -include_lib("webmachine/include/webmachine.hrl"). init([]) -> {ok, "Hello,
world"}. to_html(Req, State) -> {io_lib:format("<html><head><title>~s</title></ head><body>~s</body></html>", [State, State]), Req, State}. generate_etag(Req, State) -> {mochihex:to_hex(crypto:md5(State)), Req, State}. encodings_provided(Req, State) -> {[{"gzip", fun(X) -> zlib:gzip(X) end}], Req, State}.
None
Content Negotiation!
-module(hello_world_resource). -export([init/1, to_html/2, to_json/2, generate_etag/2]). -export([encodings_provided/2, content_types_provided/2]). -include_lib("webmachine/include/webmachine.hrl"). init([]) ->
{ok, "Hello, world"}. content_types_provided(Req, State) -> {[{"text/html", to_html}, {"application/json", to_json}], Req, State}. to_json(Req, State) -> {mochijson2:encode({struct, [{greeting, list_to_binary(State)}]}), Req, State}. to_html(Req, State) -> {io_lib:format("<html><head><title>~s</title></ head><body>~s</body></html>", [State, State]), Req, State}. %% ...
None
Resource! Implementation! Pattern!
f(Req, State) -> {RetVal, Req, State}.
Manipulating! Requests or Responses!
wrq:get_req_header(HeaderName, Req) -> 'undefined' | HeaderValue
wrq:set_resp_header( HeaderName, HeaderValue, Req) -> NewReq.
to_json(Req, State) -> {mochijson2:encode({struct, [{greeting, list_to_binary(State)}]} ), wrq:set_resp_header( "Content-Type", "application/json",
Req), State}.
None
Visual Debugging!
None
curl -v -Haccept:application/xml 127.0.0.1:8000
Basic URL Dispatch!
{["a"], some_resource, []}
{["a"], some_resource, []}
{["a"], some_resource, []}
Fancy URL Dispatch!
% The atom '*' is a wildcard {["a", '*'], some_resource,
[]} % matches /a/b/c or /a/b/c/d
% bind 2nd element to 'foo' {["a", foo], some_resource, []}
% retrieve with % wrq:path_info(foo, Req) % URL of /a/b returns "b"
% bind 2nd element to 'foo' {["a", foo], some_resource, []}
% /a/b/c/d => 404 Not Found
% dispatch /a/b/c/d {["a", foo, '*'], some_resource, []}
Handling POST!
• allowed_methods/2 • post_is_create/2 • create_path/2 • content_types_accepted/2 • handler
functions!
Other cool stuff:! • Streaming requests/ responses! • File uploads!
Resources:! • https://github.com/basho/webmachine! • https://github.com/mrallen1/wm_hello! • https://speakerdeck.com/mrallen1/ intro_to_webmachine!
Thank you!! ! Questions?!