SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Dernier

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
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
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
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: 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
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Dernier (20)

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
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 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
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: 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
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

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