SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
umleitung
an intro to mochiweb and CouchDB
mochiweb

• get mochiweb
•   svn checkout http://mochiweb.googlecode.com/svn/
    trunk/ mochiweb


• create new application
•   mochiweb/scripts/new_mochiweb.erl umleitung
run mochiweb

• make the project and run it
•   cd umleitung

•   make

•   ./start-dev.sh


• go to http://localhost:8000
directory structure

• we have our sources in /src
• we have our compiled binaries in /ebin
• the only file we need in the moment is:
      src/umleitung_web.erl
• open it in your editor
act on GET/HEAD
Method when Method =:= 'GET'; Method =:= 'HEAD' ->

 case lookup(Path) of

    {ok, Dest} ->

        Req:respond({200, [], Dest});

    _ ->

        Req:respond({501, [], quot;errorquot;})

 end;
the lookup/1
%% Internal API



lookup(Path) ->

      io:format(quot;Path is: ~s~nquot;, [Path]),

      {ok, Path}.

...
testing

• recompile and see that the running project
  is reloaded
  • to recompile just run make
• request http://localhost:8000/test
• look at the console output as well
CouchDB
• get CouchDB from http://
  couchdb.apache.org
• best compile from source
• http://wiki.apache.org/couchdb/
  Installing_from_source
• run couchdb (sudo couchdb)
• start futon on http://localhost:5984/_utils
create DB
• click on “create database”
• name it “umleitung”
• create a document:
      type: redir
      path: test
      destination: http://ideegeo.com
create view
• select the view: Custom query...
• in the map function add:
  function(doc) {

      if(doc.type == 'redir'){

          emit(doc.path, doc.destination);

      }

  }
create view 2

• choose save as
• name the design document: _design/redir
• and the view: match
what we have

• we have a mochiweb server interpreting
  our path
• we have a couchdb that can save
  path:destination tuples
• ... lets connect them
erlang_couchdb
• based on mochiweb
• slim library, small foot print
•   git clone git://github.com/ngerakines/
    erlang_couchdb.git

•   cd erlang_couchdb

•   make dist-src


• and link it to /deps (ext. dependencies)
the view request

• erlang_couchdb:invoke_view({quot;HOSTquot;,
  PORT}, quot;DBquot;, quot;DESIGN DOCquot;, quot;VIEWquot;,
  [{quot;keyquot;, quot;quot;quot; ++ REQUEST KEY ++ quot;quot;quot;}]),
• our request key is the “Path” variable that
  holds the path we want to match against
• note the enclosing ‘quot;’
major tuple hacking
• the erlang_couchdb lib is small, that means
  less comfort
• the data structure is deep nested json tuples
• the view request looks like this:
  {json,{struct, Props}} =
  erlang_couchdb:invoke_view( {quot;localhostquot;, 5984},
  quot;umleitungquot;, quot;redirquot;, quot;matchquot;, [{quot;keyquot;, quot;quot;quot; ++ Path
  ++ quot;quot;quot;}]),
fiddle it together
lookup(Path) ->
    io:format(quot;PATH: ~s~nquot;, [Path]),
   {json,{struct, Props}} =
      erlang_couchdb:invoke_view({quot;localhostquot;,
      5984}, quot;umleitungquot;, quot;redirquot;, quot;matchquot;,
      [{quot;keyquot;, quot;quot;quot; ++ Path ++ quot;quot;quot;}]),
    try proplists:get_value(<<quot;rowsquot;>>, Props) of
      [{struct, Rows} | _] ->
         {ok, proplists:get_value(<<quot;valuequot;>>, Rows)};
      _ -> {error, unknown}
    catch
         _:_ -> {error, unknown}
    end.
testing
• recompile the project again
• go to http://localhost:8000/test
• then go to http://localhost:8000/bla
• we have connected CouchDB to our
   mochiweb server
• ... relax ...
do the redirect

• the final step is doing the redirect now
• change the response line to:
  Req:respond({302, [{quot;Locationquot;, Dest}], quot;quot;});


• recompile
• reload the http://localhost:8000/test
cosmetics
• getting rid of that ugly compile warning and
  serving a static file
  case lookup(Path) of
       {ok, Dest} ->
           Req:respond({302, [{quot;Locationquot;, Dest}], quot;quot;});
        _ ->
           Req:serve_file(quot;404.htmlquot;, DocRoot)
  end;



• add a 404.html to priv/www/
and now?

• sources are on github
• git clone git://github.com/norbu09/
  umleitung.git
• go out and play, extend, rewrite it
• add a web interface (based on nitrogen?)
hope you enjoyed it
          lenz@ideegeo.com

http://github.com/norbu09/umleitung/tree

Más contenido relacionado

La actualidad más candente

Database schema management in Ruby apps
Database schema management in Ruby appsDatabase schema management in Ruby apps
Database schema management in Ruby appsVsevolod Romashov
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajaxSynapseindiappsdevelopment
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultBram Vogelaar
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul ConnectBram Vogelaar
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...andreaslubbe
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueGleicon Moraes
 
MongoDB Command Line Tools
MongoDB Command Line ToolsMongoDB Command Line Tools
MongoDB Command Line ToolsRainforest QA
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Clusterguestd34230
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in VaultGlynnForrest
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The ApproachHaci Murat Yaman
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Tom Croucher
 
Raymond Kuiper - Working the API like a Unix Pro
Raymond Kuiper - Working the API like a Unix ProRaymond Kuiper - Working the API like a Unix Pro
Raymond Kuiper - Working the API like a Unix ProZabbix
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit universityMandakini Kumari
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
Phorum MySQL tricks
Phorum MySQL tricksPhorum MySQL tricks
Phorum MySQL tricksguestd34230
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stackBram Vogelaar
 

La actualidad más candente (20)

Database schema management in Ruby apps
Database schema management in Ruby appsDatabase schema management in Ruby apps
Database schema management in Ruby apps
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul Connect
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
D2
D2D2
D2
 
Ruby meetup ROM
Ruby meetup ROMRuby meetup ROM
Ruby meetup ROM
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
MongoDB Command Line Tools
MongoDB Command Line ToolsMongoDB Command Line Tools
MongoDB Command Line Tools
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in Vault
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Raymond Kuiper - Working the API like a Unix Pro
Raymond Kuiper - Working the API like a Unix ProRaymond Kuiper - Working the API like a Unix Pro
Raymond Kuiper - Working the API like a Unix Pro
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Phorum MySQL tricks
Phorum MySQL tricksPhorum MySQL tricks
Phorum MySQL tricks
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 

Similar a Umleitung: a tiny mochiweb/CouchDB app

Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceJesse Vincent
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBRob Tweed
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceJesse Vincent
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourPeter Friese
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDBbenaldred
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxbobmcwhirter
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Bastian Feder
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 

Similar a Umleitung: a tiny mochiweb/CouchDB app (20)

Capistrano2
Capistrano2Capistrano2
Capistrano2
 
Vidoop CouchDB Talk
Vidoop CouchDB TalkVidoop CouchDB Talk
Vidoop CouchDB Talk
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
 
Capistrano
CapistranoCapistrano
Capistrano
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
Sinatra
SinatraSinatra
Sinatra
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 

Más de Lenz Gschwendtner (13)

Docker intro
Docker introDocker intro
Docker intro
 
Scaling web apps_with_message_queues
Scaling web apps_with_message_queuesScaling web apps_with_message_queues
Scaling web apps_with_message_queues
 
Iwmn architecture
Iwmn architectureIwmn architecture
Iwmn architecture
 
Linuxconf 2011 parallel languages talk
Linuxconf 2011 parallel languages talkLinuxconf 2011 parallel languages talk
Linuxconf 2011 parallel languages talk
 
Cloud architectures
Cloud architecturesCloud architectures
Cloud architectures
 
No sql
No sqlNo sql
No sql
 
Url ux
Url uxUrl ux
Url ux
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
realising ideas
realising ideasrealising ideas
realising ideas
 
The Eye
The EyeThe Eye
The Eye
 
MPI, Erlang and the web
MPI, Erlang and the webMPI, Erlang and the web
MPI, Erlang and the web
 
RabbitMQ for Perl mongers
RabbitMQ for Perl mongersRabbitMQ for Perl mongers
RabbitMQ for Perl mongers
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 

Último

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

Umleitung: a tiny mochiweb/CouchDB app

  • 1. umleitung an intro to mochiweb and CouchDB
  • 2. mochiweb • get mochiweb • svn checkout http://mochiweb.googlecode.com/svn/ trunk/ mochiweb • create new application • mochiweb/scripts/new_mochiweb.erl umleitung
  • 3. run mochiweb • make the project and run it • cd umleitung • make • ./start-dev.sh • go to http://localhost:8000
  • 4. directory structure • we have our sources in /src • we have our compiled binaries in /ebin • the only file we need in the moment is: src/umleitung_web.erl • open it in your editor
  • 5. act on GET/HEAD Method when Method =:= 'GET'; Method =:= 'HEAD' -> case lookup(Path) of {ok, Dest} -> Req:respond({200, [], Dest}); _ -> Req:respond({501, [], quot;errorquot;}) end;
  • 6. the lookup/1 %% Internal API lookup(Path) -> io:format(quot;Path is: ~s~nquot;, [Path]), {ok, Path}. ...
  • 7. testing • recompile and see that the running project is reloaded • to recompile just run make • request http://localhost:8000/test • look at the console output as well
  • 8. CouchDB • get CouchDB from http:// couchdb.apache.org • best compile from source • http://wiki.apache.org/couchdb/ Installing_from_source • run couchdb (sudo couchdb) • start futon on http://localhost:5984/_utils
  • 9. create DB • click on “create database” • name it “umleitung” • create a document: type: redir path: test destination: http://ideegeo.com
  • 10. create view • select the view: Custom query... • in the map function add: function(doc) { if(doc.type == 'redir'){ emit(doc.path, doc.destination); } }
  • 11. create view 2 • choose save as • name the design document: _design/redir • and the view: match
  • 12. what we have • we have a mochiweb server interpreting our path • we have a couchdb that can save path:destination tuples • ... lets connect them
  • 13. erlang_couchdb • based on mochiweb • slim library, small foot print • git clone git://github.com/ngerakines/ erlang_couchdb.git • cd erlang_couchdb • make dist-src • and link it to /deps (ext. dependencies)
  • 14. the view request • erlang_couchdb:invoke_view({quot;HOSTquot;, PORT}, quot;DBquot;, quot;DESIGN DOCquot;, quot;VIEWquot;, [{quot;keyquot;, quot;quot;quot; ++ REQUEST KEY ++ quot;quot;quot;}]), • our request key is the “Path” variable that holds the path we want to match against • note the enclosing ‘quot;’
  • 15. major tuple hacking • the erlang_couchdb lib is small, that means less comfort • the data structure is deep nested json tuples • the view request looks like this: {json,{struct, Props}} = erlang_couchdb:invoke_view( {quot;localhostquot;, 5984}, quot;umleitungquot;, quot;redirquot;, quot;matchquot;, [{quot;keyquot;, quot;quot;quot; ++ Path ++ quot;quot;quot;}]),
  • 16. fiddle it together lookup(Path) -> io:format(quot;PATH: ~s~nquot;, [Path]), {json,{struct, Props}} = erlang_couchdb:invoke_view({quot;localhostquot;, 5984}, quot;umleitungquot;, quot;redirquot;, quot;matchquot;, [{quot;keyquot;, quot;quot;quot; ++ Path ++ quot;quot;quot;}]), try proplists:get_value(<<quot;rowsquot;>>, Props) of [{struct, Rows} | _] -> {ok, proplists:get_value(<<quot;valuequot;>>, Rows)}; _ -> {error, unknown} catch _:_ -> {error, unknown} end.
  • 17. testing • recompile the project again • go to http://localhost:8000/test • then go to http://localhost:8000/bla • we have connected CouchDB to our mochiweb server • ... relax ...
  • 18. do the redirect • the final step is doing the redirect now • change the response line to: Req:respond({302, [{quot;Locationquot;, Dest}], quot;quot;}); • recompile • reload the http://localhost:8000/test
  • 19. cosmetics • getting rid of that ugly compile warning and serving a static file case lookup(Path) of {ok, Dest} -> Req:respond({302, [{quot;Locationquot;, Dest}], quot;quot;}); _ -> Req:serve_file(quot;404.htmlquot;, DocRoot) end; • add a 404.html to priv/www/
  • 20. and now? • sources are on github • git clone git://github.com/norbu09/ umleitung.git • go out and play, extend, rewrite it • add a web interface (based on nitrogen?)
  • 21. hope you enjoyed it lenz@ideegeo.com http://github.com/norbu09/umleitung/tree