SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante 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
 

Semelhante 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
 

Mais 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

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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