SlideShare une entreprise Scribd logo
1  sur  147
Télécharger pour lire hors ligne
CouchDB application development
                    Developing and deploying CouchApps


                     Jakob Westhoff <jakob@php.net>



                             PHPBarcamp.at
                              May 1, 2010




http://westhoffswelt.de      jakob@westhoffswelt.de        slide: 1 / 35
About Me



        Jakob Westhoff

              PHP developer for more several years
              Computer science student at the TU Dortmund

              Co-Founder of the PHP Usergroup Dortmund
              Active in different Open Source projects




http://westhoffswelt.de        jakob@westhoffswelt.de         slide: 2 / 35
Asking the audience



         Who is actively using CouchDB?
         Who played with CouchDB just for fun?
         Who has heard of CouchDB, but never used it?

         Who has already developed a CouchApp?
         Who does not know at all, what a CouchApp is?




 http://westhoffswelt.de    jakob@westhoffswelt.de         slide: 3 / 35
Asking the audience



         Who is actively using CouchDB?
         Who played with CouchDB just for fun?
         Who has heard of CouchDB, but never used it?

         Who has already developed a CouchApp?
         Who does not know at all, what a CouchApp is?




 http://westhoffswelt.de    jakob@westhoffswelt.de         slide: 3 / 35
Asking the audience



         Who is actively using CouchDB?
         Who played with CouchDB just for fun?
         Who has heard of CouchDB, but never used it?

         Who has already developed a CouchApp?
         Who does not know at all, what a CouchApp is?




 http://westhoffswelt.de    jakob@westhoffswelt.de         slide: 3 / 35
Asking the audience



         Who is actively using CouchDB?
         Who played with CouchDB just for fun?
         Who has heard of CouchDB, but never used it?

         Who has already developed a CouchApp?
         Who does not know at all, what a CouchApp is?




 http://westhoffswelt.de    jakob@westhoffswelt.de         slide: 3 / 35
Asking the audience



         Who is actively using CouchDB?
         Who played with CouchDB just for fun?
         Who has heard of CouchDB, but never used it?

         Who has already developed a CouchApp?
         Who does not know at all, what a CouchApp is?




 http://westhoffswelt.de    jakob@westhoffswelt.de         slide: 3 / 35
Goals of this session



         Understand what a CouchApp actually is
         Learn what features of CouchDB can be used to realize a
         CouchApp
         Get a glimpse of third party tools and frameworks for
         CouchApp development




 http://westhoffswelt.de     jakob@westhoffswelt.de          slide: 4 / 35
Goals of this session



         Understand what a CouchApp actually is
         Learn what features of CouchDB can be used to realize a
         CouchApp
         Get a glimpse of third party tools and frameworks for
         CouchApp development




 http://westhoffswelt.de     jakob@westhoffswelt.de          slide: 4 / 35
Goals of this session



         Understand what a CouchApp actually is
         Learn what features of CouchDB can be used to realize a
         CouchApp
         Get a glimpse of third party tools and frameworks for
         CouchApp development




 http://westhoffswelt.de     jakob@westhoffswelt.de          slide: 4 / 35
What is CouchDB?



        Document based NoSQL database
        Written in Erlang
        MapReduce based indexing
        Javascript uses as embedded language
        RESTful JSON API
        Build in incremental bi-directional replication




http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 5 / 35
What is CouchDB?



        Document based NoSQL database
        Written in Erlang
        MapReduce based indexing
        Javascript uses as embedded language
        RESTful JSON API
        Build in incremental bi-directional replication




http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 5 / 35
What is CouchDB?



        Document based NoSQL database
        Written in Erlang
        MapReduce based indexing
        Javascript uses as embedded language
        RESTful JSON API
        Build in incremental bi-directional replication




http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 5 / 35
What is CouchDB?



        Document based NoSQL database
        Written in Erlang
        MapReduce based indexing
        Javascript uses as embedded language
        RESTful JSON API
        Build in incremental bi-directional replication




http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 5 / 35
What is CouchDB?



        Document based NoSQL database
        Written in Erlang
        MapReduce based indexing
        Javascript uses as embedded language
        RESTful JSON API
        Build in incremental bi-directional replication




http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 5 / 35
What is CouchDB?



        Document based NoSQL database
        Written in Erlang
        MapReduce based indexing
        Javascript uses as embedded language
        RESTful JSON API
        Build in incremental bi-directional replication




http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 5 / 35
CouchDB document example

         Documents are stored as JSON

     {
         ” i d ” : ” r e c i p e −some−r e c i p e ” ,
         ” r e v ” : ”1−859 e 8 f 9 a 0 6 b 8 6 4 e b c a 3 a 9 2 9 7 5 0 c 1 7 5 3 7 ” ,
         ” date ” : 1270067388 ,
         ” t i t l e ” : ”Some r e c i p e ” ,
         ”ingredients”: [
             ” Sugar ” ,
         ” Flour ”
         ],
         ” i n s t r u c t i o n s ” : ”Some i n s t r u c t i o n s ” ,
         ” u s e r ” : ” u s e r −f o o b a r ” ,
     }




http://westhoffswelt.de               jakob@westhoffswelt.de                         slide: 6 / 35
CouchDB document example

         Documents are stored as JSON

     {
         ” i d ” : ” r e c i p e −some−r e c i p e ” ,
         ” r e v ” : ”1−859 e 8 f 9 a 0 6 b 8 6 4 e b c a 3 a 9 2 9 7 5 0 c 1 7 5 3 7 ” ,
         ” date ” : 1270067388 ,
         ” t i t l e ” : ”Some r e c i p e ” ,
         ”ingredients”: [
             ” Sugar ” ,
         ” Flour ”
         ],
         ” i n s t r u c t i o n s ” : ”Some i n s t r u c t i o n s ” ,
         ” u s e r ” : ” u s e r −f o o b a r ” ,
     }




http://westhoffswelt.de               jakob@westhoffswelt.de                         slide: 6 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
What is a CouchApp?


         Application build on top of CouchDB which fits the following
         criteria:
               Using CouchDB as data store
               Stored inside the CouchDB
               Served using the CouchDB Http-Server
         Most CouchApps are
               Mostly written in Javascript
               Using some sort of Javascript library
         CouchDB replication can be used to deploy applications




 http://westhoffswelt.de        jakob@westhoffswelt.de     slide: 7 / 35
Excursion: Futon
         Futon is CouchDBs adminstration interface
         Automatically available on every CouchDB
               http://localhost:5984/ utils/




 http://westhoffswelt.de     jakob@westhoffswelt.de    slide: 8 / 35
Excursion: Futon
         Futon is CouchDBs adminstration interface
         Automatically available on every CouchDB
               http://localhost:5984/ utils/




 http://westhoffswelt.de     jakob@westhoffswelt.de    slide: 8 / 35
Excursion: Futon
         Futon is CouchDBs adminstration interface
         Automatically available on every CouchDB
               http://localhost:5984/ utils/




 http://westhoffswelt.de     jakob@westhoffswelt.de    slide: 8 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
Which CouchDB Version to use?



         CouchDB 0.11 or greater
               User management
               Authentication API: Cookie, OAuth, plain-HTTP
               Per-db reader access lists
               Validation functions
               Url rewriting
               Vhost configuration




 http://westhoffswelt.de       jakob@westhoffswelt.de            slide: 9 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
CouchApp techniques


         Store all application files as document attachments
               Attachments can be stored for any document inside CouchDB
               Can be directly accesed using the RESTful interface
         Use CouchDBs authentication backend for user management
         Use validation function for access restrictions
         Use show and list functions to output HTML
         Access CouchDB using Javascript and XHR
         Use CouchDB vhosts and url rewriting for nice urls




 http://westhoffswelt.de       jakob@westhoffswelt.de         slide: 10 / 35
Authentication backend: User Management

   Managing users:
         Futon:




         RESTful API:
               Create a new document in the users database
               http://localhost:5984/ users/org.couchdb.user:foo




 http://westhoffswelt.de     jakob@westhoffswelt.de     slide: 11 / 35
Authentication backend: User Management

   Managing users:
         Futon:




         RESTful API:
               Create a new document in the users database
               http://localhost:5984/ users/org.couchdb.user:foo




 http://westhoffswelt.de     jakob@westhoffswelt.de     slide: 11 / 35
Authentication backend: User Management

   Managing users:
         Futon:




         RESTful API:
               Create a new document in the users database
               http://localhost:5984/ users/org.couchdb.user:foo




 http://westhoffswelt.de     jakob@westhoffswelt.de     slide: 11 / 35
Authentication backend: Logging in (Cookie)

   Logging in:
         POST username and password to
               http://localhost:5984/ session

         Parameters user and password
         application/x-www-form-urlencoded encoded


         Post:
         name=f o o&p a s s w o r d=b a r

         Response:
         { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] }




 http://westhoffswelt.de               jakob@westhoffswelt.de                slide: 12 / 35
Authentication backend: Logging in (Cookie)

   Logging in:
         POST username and password to
               http://localhost:5984/ session

         Parameters user and password
         application/x-www-form-urlencoded encoded


         Post:
         name=f o o&p a s s w o r d=b a r

         Response:
         { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] }




 http://westhoffswelt.de               jakob@westhoffswelt.de                slide: 12 / 35
Authentication backend: Logging in (Cookie)

   Logging in:
         POST username and password to
               http://localhost:5984/ session

         Parameters user and password
         application/x-www-form-urlencoded encoded


         Post:
         name=f o o&p a s s w o r d=b a r

         Response:
         { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] }




 http://westhoffswelt.de               jakob@westhoffswelt.de                slide: 12 / 35
Authentication backend: Logging in (Cookie)

   Logging in:
         POST username and password to
               http://localhost:5984/ session

         Parameters user and password
         application/x-www-form-urlencoded encoded


         Post:
         name=f o o&p a s s w o r d=b a r

         Response:
         { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] }




 http://westhoffswelt.de               jakob@westhoffswelt.de                slide: 12 / 35
Authentication backend: Logging in (Cookie)

   Logging in:
         POST username and password to
               http://localhost:5984/ session

         Parameters user and password
         application/x-www-form-urlencoded encoded


         Post:
         name=f o o&p a s s w o r d=b a r

         Response:
         { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] }




 http://westhoffswelt.de               jakob@westhoffswelt.de                slide: 12 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Excursion: Design documents


         Design documents supply certain special functionallities per db
         Stored with special id design/some-id
         Multiple design documents allowed per database

         Used to define:
               View functions (Map&Reduce)
               List functions
               Show functions
               Validation functions
               ...




 http://westhoffswelt.de      jakob@westhoffswelt.de         slide: 13 / 35
Validation functions: Validate updates


         Validation of document creations or updates using Javascript
         functions
         Registration: Property validate doc update on any design
         document
         Multiple validation functions on different design documents
         possible
               Called one after another
               No defined execution order: Functions need to be isolated
               One fails: validation fails




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 14 / 35
Validation functions: Validate updates


         Validation of document creations or updates using Javascript
         functions
         Registration: Property validate doc update on any design
         document
         Multiple validation functions on different design documents
         possible
               Called one after another
               No defined execution order: Functions need to be isolated
               One fails: validation fails




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 14 / 35
Validation functions: Validate updates


         Validation of document creations or updates using Javascript
         functions
         Registration: Property validate doc update on any design
         document
         Multiple validation functions on different design documents
         possible
               Called one after another
               No defined execution order: Functions need to be isolated
               One fails: validation fails




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 14 / 35
Validation functions: Validate updates


         Validation of document creations or updates using Javascript
         functions
         Registration: Property validate doc update on any design
         document
         Multiple validation functions on different design documents
         possible
               Called one after another
               No defined execution order: Functions need to be isolated
               One fails: validation fails




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 14 / 35
Validation functions: Validate updates


         Validation of document creations or updates using Javascript
         functions
         Registration: Property validate doc update on any design
         document
         Multiple validation functions on different design documents
         possible
               Called one after another
               No defined execution order: Functions need to be isolated
               One fails: validation fails




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 14 / 35
Validation functions: Validate updates


         Validation of document creations or updates using Javascript
         functions
         Registration: Property validate doc update on any design
         document
         Multiple validation functions on different design documents
         possible
               Called one after another
               No defined execution order: Functions need to be isolated
               One fails: validation fails




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 14 / 35
Validation functions: Validate updates II

          Example
               Ensure all documents have a type field
               added is not allowed to be changed after document creation

      f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) {
          i f ( ! newDoc . t y p e ) {
             throw ( { f o r b i d d e n : ” Mandatory f i e l d   ’ type ’ i s
                     m i s s i n g ” }) ;
          }

          i f ( ol dD oc && toJSON ( oldDoc . added ) != toJSON ( newDoc
               . added ) ) {
             throw ( . . . )
          }
      }




 http://westhoffswelt.de          jakob@westhoffswelt.de                  slide: 15 / 35
Validation functions: Validate updates II

          Example
               Ensure all documents have a type field
               added is not allowed to be changed after document creation

      f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) {
          i f ( ! newDoc . t y p e ) {
             throw ( { f o r b i d d e n : ” Mandatory f i e l d   ’ type ’ i s
                     m i s s i n g ” }) ;
          }

          i f ( ol dD oc && toJSON ( oldDoc . added ) != toJSON ( newDoc
               . added ) ) {
             throw ( . . . )
          }
      }




 http://westhoffswelt.de          jakob@westhoffswelt.de                  slide: 15 / 35
Validation functions: Validate updates II

          Example
               Ensure all documents have a type field
               added is not allowed to be changed after document creation

      f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) {
          i f ( ! newDoc . t y p e ) {
             throw ( { f o r b i d d e n : ” Mandatory f i e l d   ’ type ’ i s
                     m i s s i n g ” }) ;
          }

          i f ( ol dD oc && toJSON ( oldDoc . added ) != toJSON ( newDoc
               . added ) ) {
             throw ( . . . )
          }
      }




 http://westhoffswelt.de          jakob@westhoffswelt.de                  slide: 15 / 35
Validation functions: Access control

          Use validation doc update function as access control
          system
               Ensure the user is logged in
               Ensure username and author field are identical

      f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) {
          i f ( ! u s e r C t x . name ) {
             throw ( { f o r b i d d e n : ”You need t o be l o g g e d i n t o
                     c h a n g e documents . ” } ) ;
          }

          i f ( ( ol dD oc && u s e r C t x . name != oldDoc . a u t h o r ) | |
               u s e r C t x . name != newDoc . a u t h o r ) {
             throw ( . . . )
          }
      }



 http://westhoffswelt.de          jakob@westhoffswelt.de                slide: 16 / 35
Validation functions: Access control

          Use validation doc update function as access control
          system
               Ensure the user is logged in
               Ensure username and author field are identical

      f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) {
          i f ( ! u s e r C t x . name ) {
             throw ( { f o r b i d d e n : ”You need t o be l o g g e d i n t o
                     c h a n g e documents . ” } ) ;
          }

          i f ( ( ol dD oc && u s e r C t x . name != oldDoc . a u t h o r ) | |
               u s e r C t x . name != newDoc . a u t h o r ) {
             throw ( . . . )
          }
      }



 http://westhoffswelt.de          jakob@westhoffswelt.de                slide: 16 / 35
Validation functions: Access control

          Use validation doc update function as access control
          system
               Ensure the user is logged in
               Ensure username and author field are identical

      f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) {
          i f ( ! u s e r C t x . name ) {
             throw ( { f o r b i d d e n : ”You need t o be l o g g e d i n t o
                     c h a n g e documents . ” } ) ;
          }

          i f ( ( ol dD oc && u s e r C t x . name != oldDoc . a u t h o r ) | |
               u s e r C t x . name != newDoc . a u t h o r ) {
             throw ( . . . )
          }
      }



 http://westhoffswelt.de          jakob@westhoffswelt.de                slide: 16 / 35
Show and list functions

         User formatted data instead of plain JSON
         Show functions format documents
         List functions format views
         Multiple show and list functions are allowed
         per-design-document

         Stored as shows and lists object

      ” shows ” : {
         ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” ,
         ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ”
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                 slide: 17 / 35
Show and list functions

         User formatted data instead of plain JSON
         Show functions format documents
         List functions format views
         Multiple show and list functions are allowed
         per-design-document

         Stored as shows and lists object

      ” shows ” : {
         ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” ,
         ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ”
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                 slide: 17 / 35
Show and list functions

         User formatted data instead of plain JSON
         Show functions format documents
         List functions format views
         Multiple show and list functions are allowed
         per-design-document

         Stored as shows and lists object

      ” shows ” : {
         ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” ,
         ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ”
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                 slide: 17 / 35
Show and list functions

         User formatted data instead of plain JSON
         Show functions format documents
         List functions format views
         Multiple show and list functions are allowed
         per-design-document

         Stored as shows and lists object

      ” shows ” : {
         ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” ,
         ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ”
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                 slide: 17 / 35
Show and list functions

         User formatted data instead of plain JSON
         Show functions format documents
         List functions format views
         Multiple show and list functions are allowed
         per-design-document

         Stored as shows and lists object

      ” shows ” : {
         ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” ,
         ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ”
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                 slide: 17 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML


         Arguments
               doc - Document to be returned
               req - Request object
                    User context
                    GET parameter
                    Accept header
                    ...
         Return value is a response object
               body - Content returned to the caller
               headers - HTML headers (Can be used to set Content-Type)
               base64 - Can be used instead of body to send binary data




 http://westhoffswelt.de       jakob@westhoffswelt.de        slide: 18 / 35
Show function to output HTML II

          Example
               Output document type and author as HTML

      f u n c t i o n ( doc , r e q ) {

          return {
             body : [
                 ”<h1>The ” ,
                 doc . t y p e ,
                 ” document h a s been c r e a t e d by ” ,
                 doc . a u t h o r ,
                 ”</h1>”
             ] . j o i n ( ”” ) ;
          };

      }



 http://westhoffswelt.de          jakob@westhoffswelt.de        slide: 19 / 35
Show function to output HTML II

          Example
               Output document type and author as HTML

      f u n c t i o n ( doc , r e q ) {

          return {
             body : [
                 ”<h1>The ” ,
                 doc . t y p e ,
                 ” document h a s been c r e a t e d by ” ,
                 doc . a u t h o r ,
                 ”</h1>”
             ] . j o i n ( ”” ) ;
          };

      }



 http://westhoffswelt.de          jakob@westhoffswelt.de        slide: 19 / 35
Show function to output HTML II

          Example
               Output document type and author as HTML

      f u n c t i o n ( doc , r e q ) {

          return {
             body : [
                 ”<h1>The ” ,
                 doc . t y p e ,
                 ” document h a s been c r e a t e d by ” ,
                 doc . a u t h o r ,
                 ”</h1>”
             ] . j o i n ( ”” ) ;
          };

      }



 http://westhoffswelt.de          jakob@westhoffswelt.de        slide: 19 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Streaming API



         Arguments
               head - Statistical data about the view
               req - Request object
         Return value is not used
         Streaming API
               getRow() - Retrieve next row from the view, or null at the end
               send(data) - Send out the next piece of data to the caller




 http://westhoffswelt.de        jakob@westhoffswelt.de           slide: 20 / 35
List functions: Example

          Example
                Output authors in list as unordered HTML list

      f u n c t i o n ( head , r e q ) {
          var cur ;

          s e n d ( ’<u l > ’ ) ;

          w h i l e ( c u r = getRow ( ) ) {
             s e n d ( ’< l i > ’ + c u r . a u t h o r + ’</ l i > ’ ) ;
          }

          s e n d ( ’</u l > ’ ) ;
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                  slide: 21 / 35
List functions: Example

          Example
                Output authors in list as unordered HTML list

      f u n c t i o n ( head , r e q ) {
          var cur ;

          s e n d ( ’<u l > ’ ) ;

          w h i l e ( c u r = getRow ( ) ) {
             s e n d ( ’< l i > ’ + c u r . a u t h o r + ’</ l i > ’ ) ;
          }

          s e n d ( ’</u l > ’ ) ;
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                  slide: 21 / 35
List functions: Example

          Example
                Output authors in list as unordered HTML list

      f u n c t i o n ( head , r e q ) {
          var cur ;

          s e n d ( ’<u l > ’ ) ;

          w h i l e ( c u r = getRow ( ) ) {
             s e n d ( ’< l i > ’ + c u r . a u t h o r + ’</ l i > ’ ) ;
          }

          s e n d ( ’</u l > ’ ) ;
      }




 http://westhoffswelt.de              jakob@westhoffswelt.de                  slide: 21 / 35
Query show and list functions



         Queried based on design document and name

         Show functions
         GET /db/ design/mydesign/ show/show-name/doc-id

         List functions
         GET /db/ design/mydesign/ list/list-name/view-name




 http://westhoffswelt.de   jakob@westhoffswelt.de      slide: 22 / 35
Query show and list functions



         Queried based on design document and name

         Show functions
         GET /db/ design/mydesign/ show/show-name/doc-id

         List functions
         GET /db/ design/mydesign/ list/list-name/view-name




 http://westhoffswelt.de   jakob@westhoffswelt.de      slide: 22 / 35
Query show and list functions



         Queried based on design document and name

         Show functions
         GET /db/ design/mydesign/ show/show-name/doc-id

         List functions
         GET /db/ design/mydesign/ list/list-name/view-name




 http://westhoffswelt.de   jakob@westhoffswelt.de      slide: 22 / 35
Show and list functions in real applications



         Use a templating system
               Javscript micro template language based on John Resigs idea
               http://github.com/furf/jquery-template
         Use integrated provides and registerType functions to
         serve multiple formats based on the accept header
         Maybe do some sort of user authentication before showing
         content




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 23 / 35
Show and list functions in real applications



         Use a templating system
               Javscript micro template language based on John Resigs idea
               http://github.com/furf/jquery-template
         Use integrated provides and registerType functions to
         serve multiple formats based on the accept header
         Maybe do some sort of user authentication before showing
         content




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 23 / 35
Show and list functions in real applications



         Use a templating system
               Javscript micro template language based on John Resigs idea
               http://github.com/furf/jquery-template
         Use integrated provides and registerType functions to
         serve multiple formats based on the accept header
         Maybe do some sort of user authentication before showing
         content




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 23 / 35
Show and list functions in real applications



         Use a templating system
               Javscript micro template language based on John Resigs idea
               http://github.com/furf/jquery-template
         Use integrated provides and registerType functions to
         serve multiple formats based on the accept header
         Maybe do some sort of user authentication before showing
         content




 http://westhoffswelt.de       jakob@westhoffswelt.de           slide: 23 / 35
Url rewriting

         Urls like this one are neither readable nor usable

   /db/ design/mydesign/ list/list-name/view-name?limit=5

         CouchDB supports internal url rewriting
               Defined as array of rewrites on any design document
      ”rewrites”: [
        {
          ” from ” : ” / i n d e x ” ,
          ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5”
        }
      ]




 http://westhoffswelt.de         jakob@westhoffswelt.de                slide: 24 / 35
Url rewriting

         Urls like this one are neither readable nor usable

   /db/ design/mydesign/ list/list-name/view-name?limit=5

         CouchDB supports internal url rewriting
               Defined as array of rewrites on any design document
      ”rewrites”: [
        {
          ” from ” : ” / i n d e x ” ,
          ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5”
        }
      ]




 http://westhoffswelt.de         jakob@westhoffswelt.de                slide: 24 / 35
Url rewriting

         Urls like this one are neither readable nor usable

   /db/ design/mydesign/ list/list-name/view-name?limit=5

         CouchDB supports internal url rewriting
               Defined as array of rewrites on any design document
      ”rewrites”: [
        {
          ” from ” : ” / i n d e x ” ,
          ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5”
        }
      ]




 http://westhoffswelt.de         jakob@westhoffswelt.de                slide: 24 / 35
Url rewriting

         Urls like this one are neither readable nor usable

   /db/ design/mydesign/ list/list-name/view-name?limit=5

         CouchDB supports internal url rewriting
               Defined as array of rewrites on any design document
      ”rewrites”: [
        {
          ” from ” : ” / i n d e x ” ,
          ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5”
        }
      ]




 http://westhoffswelt.de         jakob@westhoffswelt.de                slide: 24 / 35
Advanced url rewriting


         Using named placeholders
               Match each path segment
      ” from ” : ” / e n t r y / : doc ” ,
      ” t o ” : ” show / show−name / : doc ”

         Using match all at the end of an url
               Appends given query parameters
      ” from ” : ” / e n t r y /∗ ” ,
      ” t o ” : ” show / show−name /∗ ”




 http://westhoffswelt.de       jakob@westhoffswelt.de   slide: 25 / 35
Advanced url rewriting


         Using named placeholders
               Match each path segment
      ” from ” : ” / e n t r y / : doc ” ,
      ” t o ” : ” show / show−name / : doc ”

         Using match all at the end of an url
               Appends given query parameters
      ” from ” : ” / e n t r y /∗ ” ,
      ” t o ” : ” show / show−name /∗ ”




 http://westhoffswelt.de       jakob@westhoffswelt.de   slide: 25 / 35
Advanced url rewriting II

         Rewriting to query parameters
      ” from ” : ” / page / : s t a r t ” ,
      ” t o ” : ” l i s t / l i s t −name/ p a g e s ” ,
      ” query ” : {
          ” startkey ”: ”: start ”
      }

         Adress a context outside of the design document
               Targets are always relative to the design document
               Relative navigation with .. is allowed
      ” from ” : ” / raw / : doc ” ,
      ” t o ” : ” . . / . . / : doc ”




 http://westhoffswelt.de             jakob@westhoffswelt.de      slide: 26 / 35
Advanced url rewriting II

         Rewriting to query parameters
      ” from ” : ” / page / : s t a r t ” ,
      ” t o ” : ” l i s t / l i s t −name/ p a g e s ” ,
      ” query ” : {
          ” startkey ”: ”: start ”
      }

         Adress a context outside of the design document
               Targets are always relative to the design document
               Relative navigation with .. is allowed
      ” from ” : ” / raw / : doc ” ,
      ” t o ” : ” . . / . . / : doc ”




 http://westhoffswelt.de             jakob@westhoffswelt.de      slide: 26 / 35
Advanced url rewriting III


           Rewriting based on HTTP methods
      {
           ” from ” : ” / e n t r y /∗ ” ,
           ” t o ” : ” show / show−name /∗ ” ,
           ” method ” : ”GET”
      },
      {
           ” from ” : ” / e n t r y /∗ ” ,
           ” t o ” : ” u p d a t e / update −name /∗ ” ,
           ” method ” : ”POST”
      },




 http://westhoffswelt.de            jakob@westhoffswelt.de   slide: 27 / 35
Query rewritten urls




         Queried on design document using special rewrite path
         /db/ design/mydesign/ rewrite/some-url

         Better, but far from being perfect → Vhost configuration




 http://westhoffswelt.de    jakob@westhoffswelt.de        slide: 28 / 35
Query rewritten urls




         Queried on design document using special rewrite path
         /db/ design/mydesign/ rewrite/some-url

         Better, but far from being perfect → Vhost configuration




 http://westhoffswelt.de    jakob@westhoffswelt.de        slide: 28 / 35
Query rewritten urls




         Queried on design document using special rewrite path
         /db/ design/mydesign/ rewrite/some-url

         Better, but far from being perfect → Vhost configuration




 http://westhoffswelt.de    jakob@westhoffswelt.de        slide: 28 / 35
Vhost configuration



         CouchDB supports url changing based on the provided Host
         Custom root path for every host/domain
         Configured in local.ini

         Direct all requests to the rewrite handler
      [ vhosts ]
      e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e




 http://westhoffswelt.de             jakob@westhoffswelt.de                    slide: 29 / 35
Vhost configuration



         CouchDB supports url changing based on the provided Host
         Custom root path for every host/domain
         Configured in local.ini

         Direct all requests to the rewrite handler
      [ vhosts ]
      e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e




 http://westhoffswelt.de             jakob@westhoffswelt.de                    slide: 29 / 35
Vhost configuration



         CouchDB supports url changing based on the provided Host
         Custom root path for every host/domain
         Configured in local.ini

         Direct all requests to the rewrite handler
      [ vhosts ]
      e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e




 http://westhoffswelt.de             jakob@westhoffswelt.de                    slide: 29 / 35
Vhost configuration



         CouchDB supports url changing based on the provided Host
         Custom root path for every host/domain
         Configured in local.ini

         Direct all requests to the rewrite handler
      [ vhosts ]
      e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e




 http://westhoffswelt.de             jakob@westhoffswelt.de                    slide: 29 / 35
Using CouchApp for deployment



         CouchApp does not only categorize these application type
         It is a utillity written in Python
               http://github.com/couchapp/couchapp
         Deployment system for CouchApps to CouchDBs
         Providing some common widgets like login or profile




 http://westhoffswelt.de     jakob@westhoffswelt.de        slide: 30 / 35
Using CouchApp for deployment



         CouchApp does not only categorize these application type
         It is a utillity written in Python
               http://github.com/couchapp/couchapp
         Deployment system for CouchApps to CouchDBs
         Providing some common widgets like login or profile




 http://westhoffswelt.de     jakob@westhoffswelt.de        slide: 30 / 35
Using CouchApp for deployment



         CouchApp does not only categorize these application type
         It is a utillity written in Python
               http://github.com/couchapp/couchapp
         Deployment system for CouchApps to CouchDBs
         Providing some common widgets like login or profile




 http://westhoffswelt.de     jakob@westhoffswelt.de        slide: 30 / 35
Using CouchApp for deployment



         CouchApp does not only categorize these application type
         It is a utillity written in Python
               http://github.com/couchapp/couchapp
         Deployment system for CouchApps to CouchDBs
         Providing some common widgets like login or profile




 http://westhoffswelt.de     jakob@westhoffswelt.de        slide: 30 / 35
CouchApp: Folder structure

         Organize your applications into a special folder structure

       .
      |−−     attachments
      |−−     id
      |−−    lists
      |−−    rewrites
      |−−   shows
       |    ‘−− myshow . j s
      |−−   updates
      |−−    validate doc update . js
      ‘−−    views
            ‘−− myview
                 |−− map . j s
                 ‘−− r e d u c e . j s




 http://westhoffswelt.de      jakob@westhoffswelt.de          slide: 31 / 35
CouchApp: Javascript preprocessing


         CouchApps preprocesses Javascript before deploying it
         Provides two useful macros: !code and !json

         // !code lib/helper/validation utillities.js
               Include Javascript code from any other file
               Reuse code throughout your application functions

         // !json lib.templates.mytemplate
               Dot notation of path to .json file
               Available using the full object path:
               lib.templates.mytemplate




 http://westhoffswelt.de         jakob@westhoffswelt.de         slide: 32 / 35
CouchApp: Javascript preprocessing


         CouchApps preprocesses Javascript before deploying it
         Provides two useful macros: !code and !json

         // !code lib/helper/validation utillities.js
               Include Javascript code from any other file
               Reuse code throughout your application functions

         // !json lib.templates.mytemplate
               Dot notation of path to .json file
               Available using the full object path:
               lib.templates.mytemplate




 http://westhoffswelt.de         jakob@westhoffswelt.de         slide: 32 / 35
CouchApp: Javascript preprocessing


         CouchApps preprocesses Javascript before deploying it
         Provides two useful macros: !code and !json

         // !code lib/helper/validation utillities.js
               Include Javascript code from any other file
               Reuse code throughout your application functions

         // !json lib.templates.mytemplate
               Dot notation of path to .json file
               Available using the full object path:
               lib.templates.mytemplate




 http://westhoffswelt.de         jakob@westhoffswelt.de         slide: 32 / 35
CouchApp: Javascript preprocessing


         CouchApps preprocesses Javascript before deploying it
         Provides two useful macros: !code and !json

         // !code lib/helper/validation utillities.js
               Include Javascript code from any other file
               Reuse code throughout your application functions

         // !json lib.templates.mytemplate
               Dot notation of path to .json file
               Available using the full object path:
               lib.templates.mytemplate




 http://westhoffswelt.de         jakob@westhoffswelt.de         slide: 32 / 35
CouchApp: Javascript preprocessing


         CouchApps preprocesses Javascript before deploying it
         Provides two useful macros: !code and !json

         // !code lib/helper/validation utillities.js
               Include Javascript code from any other file
               Reuse code throughout your application functions

         // !json lib.templates.mytemplate
               Dot notation of path to .json file
               Available using the full object path:
               lib.templates.mytemplate




 http://westhoffswelt.de         jakob@westhoffswelt.de         slide: 32 / 35
CouchApp: Javascript preprocessing


         CouchApps preprocesses Javascript before deploying it
         Provides two useful macros: !code and !json

         // !code lib/helper/validation utillities.js
               Include Javascript code from any other file
               Reuse code throughout your application functions

         // !json lib.templates.mytemplate
               Dot notation of path to .json file
               Available using the full object path:
               lib.templates.mytemplate




 http://westhoffswelt.de         jakob@westhoffswelt.de         slide: 32 / 35
CouchApp: Deployment

         Specifying all parameters on the commandline

     couchapp push http://user:pw@localhost:5984/mydb
         Use .couchapprc file
     {
         ” env ” : {
            ” default ”: {
               ” db ” : ” h t t p : / / u s e r : p w @ l o c a l h o s t : 5 9 8 4 / mydb−dev ”
            },
            ” production ” : {
               ” db ” : ” h t t p : / / / u s e r : pw@example . com/mydb”
            }
         }
     }




http://westhoffswelt.de               jakob@westhoffswelt.de                      slide: 33 / 35
CouchApp: Deployment

         Specifying all parameters on the commandline

     couchapp push http://user:pw@localhost:5984/mydb
         Use .couchapprc file
     {
         ” env ” : {
            ” default ”: {
               ” db ” : ” h t t p : / / u s e r : p w @ l o c a l h o s t : 5 9 8 4 / mydb−dev ”
            },
            ” production ” : {
               ” db ” : ” h t t p : / / / u s e r : pw@example . com/mydb”
            }
         }
     }




http://westhoffswelt.de               jakob@westhoffswelt.de                      slide: 33 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Further reading

         Things we didn’t have time to discuss
               Update functions
                    http://wiki.apache.org/couchdb/Document Update Handlers

               View functions
                    http://wiki.apache.org/couchdb/Introduction to CouchDB views

                changes stream
                    http://books.couchdb.org/relax/reference/change-notifications

               Evently javascript library
                    http://vimeo.com/9847214


         Further documentation
               CouchDB: The definitive guide
                    http://books.couchdb.org/relax/

               The CouchDB wiki
                    http://wiki.apache.org/couchdb/




 http://westhoffswelt.de           jakob@westhoffswelt.de                       slide: 34 / 35
Thanks for listening


          Questions, comments or annotations?


         Slides: http://westhoffswelt.de/portfolio.htm
                Contact: Jakob Westhoff <jakob@php.net>
                          Twitter: @jakobwesthoff

      Please leave comments and vote at: http://joind.in/1612




 http://westhoffswelt.de    jakob@westhoffswelt.de    slide: 35 / 35

Contenu connexe

Tendances

Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine ProjectDaniel Lima
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik
 
DaNode - A home made web server in D
DaNode - A home made web server in DDaNode - A home made web server in D
DaNode - A home made web server in DAndrei Alexandrescu
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPressTaylor Lovett
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS Mahboob Nur
 
An introduction to CouchDB
An introduction to CouchDBAn introduction to CouchDB
An introduction to CouchDBDavid Coallier
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Toolfilmprog
 
Building Awesome CLI apps in Go
Building Awesome CLI apps in GoBuilding Awesome CLI apps in Go
Building Awesome CLI apps in GoSteven Francia
 
Migrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons LearnedMigrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons LearnedNick Manning
 
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)Sammy Fung
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStationArabNet ME
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
Basic Introduction About API Web Service
Basic Introduction About API Web ServiceBasic Introduction About API Web Service
Basic Introduction About API Web ServiceHiraq Citra M
 

Tendances (20)

Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine Project
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
DaNode - A home made web server in D
DaNode - A home made web server in DDaNode - A home made web server in D
DaNode - A home made web server in D
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
 
An introduction to CouchDB
An introduction to CouchDBAn introduction to CouchDB
An introduction to CouchDB
 
Intro to Web Standards
Intro to Web StandardsIntro to Web Standards
Intro to Web Standards
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Tool
 
JSOP in 60 seconds
JSOP in 60 secondsJSOP in 60 seconds
JSOP in 60 seconds
 
Building Awesome CLI apps in Go
Building Awesome CLI apps in GoBuilding Awesome CLI apps in Go
Building Awesome CLI apps in Go
 
Migrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons LearnedMigrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons Learned
 
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
Web scraping 1 2-3 with python + scrapy (Summer BarCampHK 2012 version)
 
Web Ninja
Web NinjaWeb Ninja
Web Ninja
 
Tthornton code4lib
Tthornton code4libTthornton code4lib
Tthornton code4lib
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStation
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in Bavaria
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
Basic Introduction About API Web Service
Basic Introduction About API Web ServiceBasic Introduction About API Web Service
Basic Introduction About API Web Service
 
php
phpphp
php
 

Similaire à Developing CouchApps

CouchDB and Rails on the Cloud
CouchDB and Rails on the CloudCouchDB and Rails on the Cloud
CouchDB and Rails on the Cloudrockyjaiswal
 
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...Lucidworks
 
Bada familiar foundations
Bada  familiar foundationsBada  familiar foundations
Bada familiar foundationsjlansdell
 
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...IndicThreads
 
Survive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and TricksSurvive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and TricksJuho Vepsäläinen
 
Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...
Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...
Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...Provectus
 
FOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBArangoDB Database
 
Softshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offlineSoftshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offlineClaire Reynaud
 
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Edward Wilde
 
Present and future of unified, portable, and efficient data processing with A...
Present and future of unified, portable, and efficient data processing with A...Present and future of unified, portable, and efficient data processing with A...
Present and future of unified, portable, and efficient data processing with A...DataWorks Summit
 
Writing Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScriptWriting Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScriptSusan Potter
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and HowBigBlueHat
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails FinalRobert Postill
 
RDF Stream Processing Tutorial: RSP implementations
RDF Stream Processing Tutorial: RSP implementationsRDF Stream Processing Tutorial: RSP implementations
RDF Stream Processing Tutorial: RSP implementationsJean-Paul Calbimonte
 
Rapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoopRapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoopRaymond Camden
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 

Similaire à Developing CouchApps (20)

ArangoDB
ArangoDBArangoDB
ArangoDB
 
CouchDB and Rails on the Cloud
CouchDB and Rails on the CloudCouchDB and Rails on the Cloud
CouchDB and Rails on the Cloud
 
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
 
Bada familiar foundations
Bada  familiar foundationsBada  familiar foundations
Bada familiar foundations
 
Handy JS Libraries
Handy JS LibrariesHandy JS Libraries
Handy JS Libraries
 
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
 
Survive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and TricksSurvive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and Tricks
 
Not only SQL
Not only SQL Not only SQL
Not only SQL
 
Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...
Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...
Data Summer Conf 2018, “Building unified Batch and Stream processing pipeline...
 
Web Services
Web ServicesWeb Services
Web Services
 
FOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDB
 
Softshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offlineSoftshake 2013 - Let's take this offline
Softshake 2013 - Let's take this offline
 
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
 
Present and future of unified, portable, and efficient data processing with A...
Present and future of unified, portable, and efficient data processing with A...Present and future of unified, portable, and efficient data processing with A...
Present and future of unified, portable, and efficient data processing with A...
 
Writing Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScriptWriting Bullet-Proof Javascript: By Using CoffeeScript
Writing Bullet-Proof Javascript: By Using CoffeeScript
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 
RDF Stream Processing Tutorial: RSP implementations
RDF Stream Processing Tutorial: RSP implementationsRDF Stream Processing Tutorial: RSP implementations
RDF Stream Processing Tutorial: RSP implementations
 
Rapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoopRapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoop
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 

Dernier

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Dernier (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Developing CouchApps

  • 1. CouchDB application development Developing and deploying CouchApps Jakob Westhoff <jakob@php.net> PHPBarcamp.at May 1, 2010 http://westhoffswelt.de jakob@westhoffswelt.de slide: 1 / 35
  • 2. About Me Jakob Westhoff PHP developer for more several years Computer science student at the TU Dortmund Co-Founder of the PHP Usergroup Dortmund Active in different Open Source projects http://westhoffswelt.de jakob@westhoffswelt.de slide: 2 / 35
  • 3. Asking the audience Who is actively using CouchDB? Who played with CouchDB just for fun? Who has heard of CouchDB, but never used it? Who has already developed a CouchApp? Who does not know at all, what a CouchApp is? http://westhoffswelt.de jakob@westhoffswelt.de slide: 3 / 35
  • 4. Asking the audience Who is actively using CouchDB? Who played with CouchDB just for fun? Who has heard of CouchDB, but never used it? Who has already developed a CouchApp? Who does not know at all, what a CouchApp is? http://westhoffswelt.de jakob@westhoffswelt.de slide: 3 / 35
  • 5. Asking the audience Who is actively using CouchDB? Who played with CouchDB just for fun? Who has heard of CouchDB, but never used it? Who has already developed a CouchApp? Who does not know at all, what a CouchApp is? http://westhoffswelt.de jakob@westhoffswelt.de slide: 3 / 35
  • 6. Asking the audience Who is actively using CouchDB? Who played with CouchDB just for fun? Who has heard of CouchDB, but never used it? Who has already developed a CouchApp? Who does not know at all, what a CouchApp is? http://westhoffswelt.de jakob@westhoffswelt.de slide: 3 / 35
  • 7. Asking the audience Who is actively using CouchDB? Who played with CouchDB just for fun? Who has heard of CouchDB, but never used it? Who has already developed a CouchApp? Who does not know at all, what a CouchApp is? http://westhoffswelt.de jakob@westhoffswelt.de slide: 3 / 35
  • 8. Goals of this session Understand what a CouchApp actually is Learn what features of CouchDB can be used to realize a CouchApp Get a glimpse of third party tools and frameworks for CouchApp development http://westhoffswelt.de jakob@westhoffswelt.de slide: 4 / 35
  • 9. Goals of this session Understand what a CouchApp actually is Learn what features of CouchDB can be used to realize a CouchApp Get a glimpse of third party tools and frameworks for CouchApp development http://westhoffswelt.de jakob@westhoffswelt.de slide: 4 / 35
  • 10. Goals of this session Understand what a CouchApp actually is Learn what features of CouchDB can be used to realize a CouchApp Get a glimpse of third party tools and frameworks for CouchApp development http://westhoffswelt.de jakob@westhoffswelt.de slide: 4 / 35
  • 11. What is CouchDB? Document based NoSQL database Written in Erlang MapReduce based indexing Javascript uses as embedded language RESTful JSON API Build in incremental bi-directional replication http://westhoffswelt.de jakob@westhoffswelt.de slide: 5 / 35
  • 12. What is CouchDB? Document based NoSQL database Written in Erlang MapReduce based indexing Javascript uses as embedded language RESTful JSON API Build in incremental bi-directional replication http://westhoffswelt.de jakob@westhoffswelt.de slide: 5 / 35
  • 13. What is CouchDB? Document based NoSQL database Written in Erlang MapReduce based indexing Javascript uses as embedded language RESTful JSON API Build in incremental bi-directional replication http://westhoffswelt.de jakob@westhoffswelt.de slide: 5 / 35
  • 14. What is CouchDB? Document based NoSQL database Written in Erlang MapReduce based indexing Javascript uses as embedded language RESTful JSON API Build in incremental bi-directional replication http://westhoffswelt.de jakob@westhoffswelt.de slide: 5 / 35
  • 15. What is CouchDB? Document based NoSQL database Written in Erlang MapReduce based indexing Javascript uses as embedded language RESTful JSON API Build in incremental bi-directional replication http://westhoffswelt.de jakob@westhoffswelt.de slide: 5 / 35
  • 16. What is CouchDB? Document based NoSQL database Written in Erlang MapReduce based indexing Javascript uses as embedded language RESTful JSON API Build in incremental bi-directional replication http://westhoffswelt.de jakob@westhoffswelt.de slide: 5 / 35
  • 17. CouchDB document example Documents are stored as JSON { ” i d ” : ” r e c i p e −some−r e c i p e ” , ” r e v ” : ”1−859 e 8 f 9 a 0 6 b 8 6 4 e b c a 3 a 9 2 9 7 5 0 c 1 7 5 3 7 ” , ” date ” : 1270067388 , ” t i t l e ” : ”Some r e c i p e ” , ”ingredients”: [ ” Sugar ” , ” Flour ” ], ” i n s t r u c t i o n s ” : ”Some i n s t r u c t i o n s ” , ” u s e r ” : ” u s e r −f o o b a r ” , } http://westhoffswelt.de jakob@westhoffswelt.de slide: 6 / 35
  • 18. CouchDB document example Documents are stored as JSON { ” i d ” : ” r e c i p e −some−r e c i p e ” , ” r e v ” : ”1−859 e 8 f 9 a 0 6 b 8 6 4 e b c a 3 a 9 2 9 7 5 0 c 1 7 5 3 7 ” , ” date ” : 1270067388 , ” t i t l e ” : ”Some r e c i p e ” , ”ingredients”: [ ” Sugar ” , ” Flour ” ], ” i n s t r u c t i o n s ” : ”Some i n s t r u c t i o n s ” , ” u s e r ” : ” u s e r −f o o b a r ” , } http://westhoffswelt.de jakob@westhoffswelt.de slide: 6 / 35
  • 19. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 20. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 21. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 22. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 23. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 24. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 25. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 26. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 27. What is a CouchApp? Application build on top of CouchDB which fits the following criteria: Using CouchDB as data store Stored inside the CouchDB Served using the CouchDB Http-Server Most CouchApps are Mostly written in Javascript Using some sort of Javascript library CouchDB replication can be used to deploy applications http://westhoffswelt.de jakob@westhoffswelt.de slide: 7 / 35
  • 28. Excursion: Futon Futon is CouchDBs adminstration interface Automatically available on every CouchDB http://localhost:5984/ utils/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 8 / 35
  • 29. Excursion: Futon Futon is CouchDBs adminstration interface Automatically available on every CouchDB http://localhost:5984/ utils/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 8 / 35
  • 30. Excursion: Futon Futon is CouchDBs adminstration interface Automatically available on every CouchDB http://localhost:5984/ utils/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 8 / 35
  • 31. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 32. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 33. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 34. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 35. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 36. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 37. Which CouchDB Version to use? CouchDB 0.11 or greater User management Authentication API: Cookie, OAuth, plain-HTTP Per-db reader access lists Validation functions Url rewriting Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 9 / 35
  • 38. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 39. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 40. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 41. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 42. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 43. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 44. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 45. CouchApp techniques Store all application files as document attachments Attachments can be stored for any document inside CouchDB Can be directly accesed using the RESTful interface Use CouchDBs authentication backend for user management Use validation function for access restrictions Use show and list functions to output HTML Access CouchDB using Javascript and XHR Use CouchDB vhosts and url rewriting for nice urls http://westhoffswelt.de jakob@westhoffswelt.de slide: 10 / 35
  • 46. Authentication backend: User Management Managing users: Futon: RESTful API: Create a new document in the users database http://localhost:5984/ users/org.couchdb.user:foo http://westhoffswelt.de jakob@westhoffswelt.de slide: 11 / 35
  • 47. Authentication backend: User Management Managing users: Futon: RESTful API: Create a new document in the users database http://localhost:5984/ users/org.couchdb.user:foo http://westhoffswelt.de jakob@westhoffswelt.de slide: 11 / 35
  • 48. Authentication backend: User Management Managing users: Futon: RESTful API: Create a new document in the users database http://localhost:5984/ users/org.couchdb.user:foo http://westhoffswelt.de jakob@westhoffswelt.de slide: 11 / 35
  • 49. Authentication backend: Logging in (Cookie) Logging in: POST username and password to http://localhost:5984/ session Parameters user and password application/x-www-form-urlencoded encoded Post: name=f o o&p a s s w o r d=b a r Response: { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] } http://westhoffswelt.de jakob@westhoffswelt.de slide: 12 / 35
  • 50. Authentication backend: Logging in (Cookie) Logging in: POST username and password to http://localhost:5984/ session Parameters user and password application/x-www-form-urlencoded encoded Post: name=f o o&p a s s w o r d=b a r Response: { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] } http://westhoffswelt.de jakob@westhoffswelt.de slide: 12 / 35
  • 51. Authentication backend: Logging in (Cookie) Logging in: POST username and password to http://localhost:5984/ session Parameters user and password application/x-www-form-urlencoded encoded Post: name=f o o&p a s s w o r d=b a r Response: { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] } http://westhoffswelt.de jakob@westhoffswelt.de slide: 12 / 35
  • 52. Authentication backend: Logging in (Cookie) Logging in: POST username and password to http://localhost:5984/ session Parameters user and password application/x-www-form-urlencoded encoded Post: name=f o o&p a s s w o r d=b a r Response: { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] } http://westhoffswelt.de jakob@westhoffswelt.de slide: 12 / 35
  • 53. Authentication backend: Logging in (Cookie) Logging in: POST username and password to http://localhost:5984/ session Parameters user and password application/x-www-form-urlencoded encoded Post: name=f o o&p a s s w o r d=b a r Response: { ” ok ” : t r u e , ”name” : ” f o o ” , ” r o l e s ” : [ ] } http://westhoffswelt.de jakob@westhoffswelt.de slide: 12 / 35
  • 54. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 55. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 56. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 57. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 58. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 59. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 60. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 61. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 62. Excursion: Design documents Design documents supply certain special functionallities per db Stored with special id design/some-id Multiple design documents allowed per database Used to define: View functions (Map&Reduce) List functions Show functions Validation functions ... http://westhoffswelt.de jakob@westhoffswelt.de slide: 13 / 35
  • 63. Validation functions: Validate updates Validation of document creations or updates using Javascript functions Registration: Property validate doc update on any design document Multiple validation functions on different design documents possible Called one after another No defined execution order: Functions need to be isolated One fails: validation fails http://westhoffswelt.de jakob@westhoffswelt.de slide: 14 / 35
  • 64. Validation functions: Validate updates Validation of document creations or updates using Javascript functions Registration: Property validate doc update on any design document Multiple validation functions on different design documents possible Called one after another No defined execution order: Functions need to be isolated One fails: validation fails http://westhoffswelt.de jakob@westhoffswelt.de slide: 14 / 35
  • 65. Validation functions: Validate updates Validation of document creations or updates using Javascript functions Registration: Property validate doc update on any design document Multiple validation functions on different design documents possible Called one after another No defined execution order: Functions need to be isolated One fails: validation fails http://westhoffswelt.de jakob@westhoffswelt.de slide: 14 / 35
  • 66. Validation functions: Validate updates Validation of document creations or updates using Javascript functions Registration: Property validate doc update on any design document Multiple validation functions on different design documents possible Called one after another No defined execution order: Functions need to be isolated One fails: validation fails http://westhoffswelt.de jakob@westhoffswelt.de slide: 14 / 35
  • 67. Validation functions: Validate updates Validation of document creations or updates using Javascript functions Registration: Property validate doc update on any design document Multiple validation functions on different design documents possible Called one after another No defined execution order: Functions need to be isolated One fails: validation fails http://westhoffswelt.de jakob@westhoffswelt.de slide: 14 / 35
  • 68. Validation functions: Validate updates Validation of document creations or updates using Javascript functions Registration: Property validate doc update on any design document Multiple validation functions on different design documents possible Called one after another No defined execution order: Functions need to be isolated One fails: validation fails http://westhoffswelt.de jakob@westhoffswelt.de slide: 14 / 35
  • 69. Validation functions: Validate updates II Example Ensure all documents have a type field added is not allowed to be changed after document creation f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) { i f ( ! newDoc . t y p e ) { throw ( { f o r b i d d e n : ” Mandatory f i e l d ’ type ’ i s m i s s i n g ” }) ; } i f ( ol dD oc && toJSON ( oldDoc . added ) != toJSON ( newDoc . added ) ) { throw ( . . . ) } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 15 / 35
  • 70. Validation functions: Validate updates II Example Ensure all documents have a type field added is not allowed to be changed after document creation f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) { i f ( ! newDoc . t y p e ) { throw ( { f o r b i d d e n : ” Mandatory f i e l d ’ type ’ i s m i s s i n g ” }) ; } i f ( ol dD oc && toJSON ( oldDoc . added ) != toJSON ( newDoc . added ) ) { throw ( . . . ) } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 15 / 35
  • 71. Validation functions: Validate updates II Example Ensure all documents have a type field added is not allowed to be changed after document creation f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) { i f ( ! newDoc . t y p e ) { throw ( { f o r b i d d e n : ” Mandatory f i e l d ’ type ’ i s m i s s i n g ” }) ; } i f ( ol dD oc && toJSON ( oldDoc . added ) != toJSON ( newDoc . added ) ) { throw ( . . . ) } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 15 / 35
  • 72. Validation functions: Access control Use validation doc update function as access control system Ensure the user is logged in Ensure username and author field are identical f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) { i f ( ! u s e r C t x . name ) { throw ( { f o r b i d d e n : ”You need t o be l o g g e d i n t o c h a n g e documents . ” } ) ; } i f ( ( ol dD oc && u s e r C t x . name != oldDoc . a u t h o r ) | | u s e r C t x . name != newDoc . a u t h o r ) { throw ( . . . ) } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 16 / 35
  • 73. Validation functions: Access control Use validation doc update function as access control system Ensure the user is logged in Ensure username and author field are identical f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) { i f ( ! u s e r C t x . name ) { throw ( { f o r b i d d e n : ”You need t o be l o g g e d i n t o c h a n g e documents . ” } ) ; } i f ( ( ol dD oc && u s e r C t x . name != oldDoc . a u t h o r ) | | u s e r C t x . name != newDoc . a u t h o r ) { throw ( . . . ) } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 16 / 35
  • 74. Validation functions: Access control Use validation doc update function as access control system Ensure the user is logged in Ensure username and author field are identical f u n c t i o n ( newDoc , oldDoc , u s e r C t x ) { i f ( ! u s e r C t x . name ) { throw ( { f o r b i d d e n : ”You need t o be l o g g e d i n t o c h a n g e documents . ” } ) ; } i f ( ( ol dD oc && u s e r C t x . name != oldDoc . a u t h o r ) | | u s e r C t x . name != newDoc . a u t h o r ) { throw ( . . . ) } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 16 / 35
  • 75. Show and list functions User formatted data instead of plain JSON Show functions format documents List functions format views Multiple show and list functions are allowed per-design-document Stored as shows and lists object ” shows ” : { ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” , ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” } http://westhoffswelt.de jakob@westhoffswelt.de slide: 17 / 35
  • 76. Show and list functions User formatted data instead of plain JSON Show functions format documents List functions format views Multiple show and list functions are allowed per-design-document Stored as shows and lists object ” shows ” : { ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” , ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” } http://westhoffswelt.de jakob@westhoffswelt.de slide: 17 / 35
  • 77. Show and list functions User formatted data instead of plain JSON Show functions format documents List functions format views Multiple show and list functions are allowed per-design-document Stored as shows and lists object ” shows ” : { ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” , ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” } http://westhoffswelt.de jakob@westhoffswelt.de slide: 17 / 35
  • 78. Show and list functions User formatted data instead of plain JSON Show functions format documents List functions format views Multiple show and list functions are allowed per-design-document Stored as shows and lists object ” shows ” : { ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” , ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” } http://westhoffswelt.de jakob@westhoffswelt.de slide: 17 / 35
  • 79. Show and list functions User formatted data instead of plain JSON Show functions format documents List functions format views Multiple show and list functions are allowed per-design-document Stored as shows and lists object ” shows ” : { ” summary ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” , ” d e t a i l ” : ” f u n c t i o n ( doc , r e q ) { . . . } ” } http://westhoffswelt.de jakob@westhoffswelt.de slide: 17 / 35
  • 80. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 81. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 82. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 83. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 84. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 85. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 86. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 87. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 88. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 89. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 90. Show function to output HTML Arguments doc - Document to be returned req - Request object User context GET parameter Accept header ... Return value is a response object body - Content returned to the caller headers - HTML headers (Can be used to set Content-Type) base64 - Can be used instead of body to send binary data http://westhoffswelt.de jakob@westhoffswelt.de slide: 18 / 35
  • 91. Show function to output HTML II Example Output document type and author as HTML f u n c t i o n ( doc , r e q ) { return { body : [ ”<h1>The ” , doc . t y p e , ” document h a s been c r e a t e d by ” , doc . a u t h o r , ”</h1>” ] . j o i n ( ”” ) ; }; } http://westhoffswelt.de jakob@westhoffswelt.de slide: 19 / 35
  • 92. Show function to output HTML II Example Output document type and author as HTML f u n c t i o n ( doc , r e q ) { return { body : [ ”<h1>The ” , doc . t y p e , ” document h a s been c r e a t e d by ” , doc . a u t h o r , ”</h1>” ] . j o i n ( ”” ) ; }; } http://westhoffswelt.de jakob@westhoffswelt.de slide: 19 / 35
  • 93. Show function to output HTML II Example Output document type and author as HTML f u n c t i o n ( doc , r e q ) { return { body : [ ”<h1>The ” , doc . t y p e , ” document h a s been c r e a t e d by ” , doc . a u t h o r , ”</h1>” ] . j o i n ( ”” ) ; }; } http://westhoffswelt.de jakob@westhoffswelt.de slide: 19 / 35
  • 94. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 95. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 96. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 97. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 98. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 99. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 100. List functions: Streaming API Arguments head - Statistical data about the view req - Request object Return value is not used Streaming API getRow() - Retrieve next row from the view, or null at the end send(data) - Send out the next piece of data to the caller http://westhoffswelt.de jakob@westhoffswelt.de slide: 20 / 35
  • 101. List functions: Example Example Output authors in list as unordered HTML list f u n c t i o n ( head , r e q ) { var cur ; s e n d ( ’<u l > ’ ) ; w h i l e ( c u r = getRow ( ) ) { s e n d ( ’< l i > ’ + c u r . a u t h o r + ’</ l i > ’ ) ; } s e n d ( ’</u l > ’ ) ; } http://westhoffswelt.de jakob@westhoffswelt.de slide: 21 / 35
  • 102. List functions: Example Example Output authors in list as unordered HTML list f u n c t i o n ( head , r e q ) { var cur ; s e n d ( ’<u l > ’ ) ; w h i l e ( c u r = getRow ( ) ) { s e n d ( ’< l i > ’ + c u r . a u t h o r + ’</ l i > ’ ) ; } s e n d ( ’</u l > ’ ) ; } http://westhoffswelt.de jakob@westhoffswelt.de slide: 21 / 35
  • 103. List functions: Example Example Output authors in list as unordered HTML list f u n c t i o n ( head , r e q ) { var cur ; s e n d ( ’<u l > ’ ) ; w h i l e ( c u r = getRow ( ) ) { s e n d ( ’< l i > ’ + c u r . a u t h o r + ’</ l i > ’ ) ; } s e n d ( ’</u l > ’ ) ; } http://westhoffswelt.de jakob@westhoffswelt.de slide: 21 / 35
  • 104. Query show and list functions Queried based on design document and name Show functions GET /db/ design/mydesign/ show/show-name/doc-id List functions GET /db/ design/mydesign/ list/list-name/view-name http://westhoffswelt.de jakob@westhoffswelt.de slide: 22 / 35
  • 105. Query show and list functions Queried based on design document and name Show functions GET /db/ design/mydesign/ show/show-name/doc-id List functions GET /db/ design/mydesign/ list/list-name/view-name http://westhoffswelt.de jakob@westhoffswelt.de slide: 22 / 35
  • 106. Query show and list functions Queried based on design document and name Show functions GET /db/ design/mydesign/ show/show-name/doc-id List functions GET /db/ design/mydesign/ list/list-name/view-name http://westhoffswelt.de jakob@westhoffswelt.de slide: 22 / 35
  • 107. Show and list functions in real applications Use a templating system Javscript micro template language based on John Resigs idea http://github.com/furf/jquery-template Use integrated provides and registerType functions to serve multiple formats based on the accept header Maybe do some sort of user authentication before showing content http://westhoffswelt.de jakob@westhoffswelt.de slide: 23 / 35
  • 108. Show and list functions in real applications Use a templating system Javscript micro template language based on John Resigs idea http://github.com/furf/jquery-template Use integrated provides and registerType functions to serve multiple formats based on the accept header Maybe do some sort of user authentication before showing content http://westhoffswelt.de jakob@westhoffswelt.de slide: 23 / 35
  • 109. Show and list functions in real applications Use a templating system Javscript micro template language based on John Resigs idea http://github.com/furf/jquery-template Use integrated provides and registerType functions to serve multiple formats based on the accept header Maybe do some sort of user authentication before showing content http://westhoffswelt.de jakob@westhoffswelt.de slide: 23 / 35
  • 110. Show and list functions in real applications Use a templating system Javscript micro template language based on John Resigs idea http://github.com/furf/jquery-template Use integrated provides and registerType functions to serve multiple formats based on the accept header Maybe do some sort of user authentication before showing content http://westhoffswelt.de jakob@westhoffswelt.de slide: 23 / 35
  • 111. Url rewriting Urls like this one are neither readable nor usable /db/ design/mydesign/ list/list-name/view-name?limit=5 CouchDB supports internal url rewriting Defined as array of rewrites on any design document ”rewrites”: [ { ” from ” : ” / i n d e x ” , ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5” } ] http://westhoffswelt.de jakob@westhoffswelt.de slide: 24 / 35
  • 112. Url rewriting Urls like this one are neither readable nor usable /db/ design/mydesign/ list/list-name/view-name?limit=5 CouchDB supports internal url rewriting Defined as array of rewrites on any design document ”rewrites”: [ { ” from ” : ” / i n d e x ” , ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5” } ] http://westhoffswelt.de jakob@westhoffswelt.de slide: 24 / 35
  • 113. Url rewriting Urls like this one are neither readable nor usable /db/ design/mydesign/ list/list-name/view-name?limit=5 CouchDB supports internal url rewriting Defined as array of rewrites on any design document ”rewrites”: [ { ” from ” : ” / i n d e x ” , ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5” } ] http://westhoffswelt.de jakob@westhoffswelt.de slide: 24 / 35
  • 114. Url rewriting Urls like this one are neither readable nor usable /db/ design/mydesign/ list/list-name/view-name?limit=5 CouchDB supports internal url rewriting Defined as array of rewrites on any design document ”rewrites”: [ { ” from ” : ” / i n d e x ” , ” t o ” : ” l i s t / l i s t −name/ view −name? l i m i t =5” } ] http://westhoffswelt.de jakob@westhoffswelt.de slide: 24 / 35
  • 115. Advanced url rewriting Using named placeholders Match each path segment ” from ” : ” / e n t r y / : doc ” , ” t o ” : ” show / show−name / : doc ” Using match all at the end of an url Appends given query parameters ” from ” : ” / e n t r y /∗ ” , ” t o ” : ” show / show−name /∗ ” http://westhoffswelt.de jakob@westhoffswelt.de slide: 25 / 35
  • 116. Advanced url rewriting Using named placeholders Match each path segment ” from ” : ” / e n t r y / : doc ” , ” t o ” : ” show / show−name / : doc ” Using match all at the end of an url Appends given query parameters ” from ” : ” / e n t r y /∗ ” , ” t o ” : ” show / show−name /∗ ” http://westhoffswelt.de jakob@westhoffswelt.de slide: 25 / 35
  • 117. Advanced url rewriting II Rewriting to query parameters ” from ” : ” / page / : s t a r t ” , ” t o ” : ” l i s t / l i s t −name/ p a g e s ” , ” query ” : { ” startkey ”: ”: start ” } Adress a context outside of the design document Targets are always relative to the design document Relative navigation with .. is allowed ” from ” : ” / raw / : doc ” , ” t o ” : ” . . / . . / : doc ” http://westhoffswelt.de jakob@westhoffswelt.de slide: 26 / 35
  • 118. Advanced url rewriting II Rewriting to query parameters ” from ” : ” / page / : s t a r t ” , ” t o ” : ” l i s t / l i s t −name/ p a g e s ” , ” query ” : { ” startkey ”: ”: start ” } Adress a context outside of the design document Targets are always relative to the design document Relative navigation with .. is allowed ” from ” : ” / raw / : doc ” , ” t o ” : ” . . / . . / : doc ” http://westhoffswelt.de jakob@westhoffswelt.de slide: 26 / 35
  • 119. Advanced url rewriting III Rewriting based on HTTP methods { ” from ” : ” / e n t r y /∗ ” , ” t o ” : ” show / show−name /∗ ” , ” method ” : ”GET” }, { ” from ” : ” / e n t r y /∗ ” , ” t o ” : ” u p d a t e / update −name /∗ ” , ” method ” : ”POST” }, http://westhoffswelt.de jakob@westhoffswelt.de slide: 27 / 35
  • 120. Query rewritten urls Queried on design document using special rewrite path /db/ design/mydesign/ rewrite/some-url Better, but far from being perfect → Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 28 / 35
  • 121. Query rewritten urls Queried on design document using special rewrite path /db/ design/mydesign/ rewrite/some-url Better, but far from being perfect → Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 28 / 35
  • 122. Query rewritten urls Queried on design document using special rewrite path /db/ design/mydesign/ rewrite/some-url Better, but far from being perfect → Vhost configuration http://westhoffswelt.de jakob@westhoffswelt.de slide: 28 / 35
  • 123. Vhost configuration CouchDB supports url changing based on the provided Host Custom root path for every host/domain Configured in local.ini Direct all requests to the rewrite handler [ vhosts ] e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e http://westhoffswelt.de jakob@westhoffswelt.de slide: 29 / 35
  • 124. Vhost configuration CouchDB supports url changing based on the provided Host Custom root path for every host/domain Configured in local.ini Direct all requests to the rewrite handler [ vhosts ] e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e http://westhoffswelt.de jakob@westhoffswelt.de slide: 29 / 35
  • 125. Vhost configuration CouchDB supports url changing based on the provided Host Custom root path for every host/domain Configured in local.ini Direct all requests to the rewrite handler [ vhosts ] e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e http://westhoffswelt.de jakob@westhoffswelt.de slide: 29 / 35
  • 126. Vhost configuration CouchDB supports url changing based on the provided Host Custom root path for every host/domain Configured in local.ini Direct all requests to the rewrite handler [ vhosts ] e x a m p l e . com = /mydb/ d e s i g n / m y d e s i g n / r e w r i t e http://westhoffswelt.de jakob@westhoffswelt.de slide: 29 / 35
  • 127. Using CouchApp for deployment CouchApp does not only categorize these application type It is a utillity written in Python http://github.com/couchapp/couchapp Deployment system for CouchApps to CouchDBs Providing some common widgets like login or profile http://westhoffswelt.de jakob@westhoffswelt.de slide: 30 / 35
  • 128. Using CouchApp for deployment CouchApp does not only categorize these application type It is a utillity written in Python http://github.com/couchapp/couchapp Deployment system for CouchApps to CouchDBs Providing some common widgets like login or profile http://westhoffswelt.de jakob@westhoffswelt.de slide: 30 / 35
  • 129. Using CouchApp for deployment CouchApp does not only categorize these application type It is a utillity written in Python http://github.com/couchapp/couchapp Deployment system for CouchApps to CouchDBs Providing some common widgets like login or profile http://westhoffswelt.de jakob@westhoffswelt.de slide: 30 / 35
  • 130. Using CouchApp for deployment CouchApp does not only categorize these application type It is a utillity written in Python http://github.com/couchapp/couchapp Deployment system for CouchApps to CouchDBs Providing some common widgets like login or profile http://westhoffswelt.de jakob@westhoffswelt.de slide: 30 / 35
  • 131. CouchApp: Folder structure Organize your applications into a special folder structure . |−− attachments |−− id |−− lists |−− rewrites |−− shows | ‘−− myshow . j s |−− updates |−− validate doc update . js ‘−− views ‘−− myview |−− map . j s ‘−− r e d u c e . j s http://westhoffswelt.de jakob@westhoffswelt.de slide: 31 / 35
  • 132. CouchApp: Javascript preprocessing CouchApps preprocesses Javascript before deploying it Provides two useful macros: !code and !json // !code lib/helper/validation utillities.js Include Javascript code from any other file Reuse code throughout your application functions // !json lib.templates.mytemplate Dot notation of path to .json file Available using the full object path: lib.templates.mytemplate http://westhoffswelt.de jakob@westhoffswelt.de slide: 32 / 35
  • 133. CouchApp: Javascript preprocessing CouchApps preprocesses Javascript before deploying it Provides two useful macros: !code and !json // !code lib/helper/validation utillities.js Include Javascript code from any other file Reuse code throughout your application functions // !json lib.templates.mytemplate Dot notation of path to .json file Available using the full object path: lib.templates.mytemplate http://westhoffswelt.de jakob@westhoffswelt.de slide: 32 / 35
  • 134. CouchApp: Javascript preprocessing CouchApps preprocesses Javascript before deploying it Provides two useful macros: !code and !json // !code lib/helper/validation utillities.js Include Javascript code from any other file Reuse code throughout your application functions // !json lib.templates.mytemplate Dot notation of path to .json file Available using the full object path: lib.templates.mytemplate http://westhoffswelt.de jakob@westhoffswelt.de slide: 32 / 35
  • 135. CouchApp: Javascript preprocessing CouchApps preprocesses Javascript before deploying it Provides two useful macros: !code and !json // !code lib/helper/validation utillities.js Include Javascript code from any other file Reuse code throughout your application functions // !json lib.templates.mytemplate Dot notation of path to .json file Available using the full object path: lib.templates.mytemplate http://westhoffswelt.de jakob@westhoffswelt.de slide: 32 / 35
  • 136. CouchApp: Javascript preprocessing CouchApps preprocesses Javascript before deploying it Provides two useful macros: !code and !json // !code lib/helper/validation utillities.js Include Javascript code from any other file Reuse code throughout your application functions // !json lib.templates.mytemplate Dot notation of path to .json file Available using the full object path: lib.templates.mytemplate http://westhoffswelt.de jakob@westhoffswelt.de slide: 32 / 35
  • 137. CouchApp: Javascript preprocessing CouchApps preprocesses Javascript before deploying it Provides two useful macros: !code and !json // !code lib/helper/validation utillities.js Include Javascript code from any other file Reuse code throughout your application functions // !json lib.templates.mytemplate Dot notation of path to .json file Available using the full object path: lib.templates.mytemplate http://westhoffswelt.de jakob@westhoffswelt.de slide: 32 / 35
  • 138. CouchApp: Deployment Specifying all parameters on the commandline couchapp push http://user:pw@localhost:5984/mydb Use .couchapprc file { ” env ” : { ” default ”: { ” db ” : ” h t t p : / / u s e r : p w @ l o c a l h o s t : 5 9 8 4 / mydb−dev ” }, ” production ” : { ” db ” : ” h t t p : / / / u s e r : pw@example . com/mydb” } } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 33 / 35
  • 139. CouchApp: Deployment Specifying all parameters on the commandline couchapp push http://user:pw@localhost:5984/mydb Use .couchapprc file { ” env ” : { ” default ”: { ” db ” : ” h t t p : / / u s e r : p w @ l o c a l h o s t : 5 9 8 4 / mydb−dev ” }, ” production ” : { ” db ” : ” h t t p : / / / u s e r : pw@example . com/mydb” } } } http://westhoffswelt.de jakob@westhoffswelt.de slide: 33 / 35
  • 140. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 141. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 142. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 143. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 144. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 145. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 146. Further reading Things we didn’t have time to discuss Update functions http://wiki.apache.org/couchdb/Document Update Handlers View functions http://wiki.apache.org/couchdb/Introduction to CouchDB views changes stream http://books.couchdb.org/relax/reference/change-notifications Evently javascript library http://vimeo.com/9847214 Further documentation CouchDB: The definitive guide http://books.couchdb.org/relax/ The CouchDB wiki http://wiki.apache.org/couchdb/ http://westhoffswelt.de jakob@westhoffswelt.de slide: 34 / 35
  • 147. Thanks for listening Questions, comments or annotations? Slides: http://westhoffswelt.de/portfolio.htm Contact: Jakob Westhoff <jakob@php.net> Twitter: @jakobwesthoff Please leave comments and vote at: http://joind.in/1612 http://westhoffswelt.de jakob@westhoffswelt.de slide: 35 / 35