From commits-return-32944-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Fri Apr 13 08:03:50 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 88E04180627 for ; Fri, 13 Apr 2018 08:03:49 +0200 (CEST) Received: (qmail 38104 invoked by uid 500); 13 Apr 2018 06:03:48 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 38095 invoked by uid 99); 13 Apr 2018 06:03:48 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Apr 2018 06:03:48 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 08D54C1FBA for ; Fri, 13 Apr 2018 06:03:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -10.301 X-Spam-Level: X-Spam-Status: No, score=-10.301 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id mXrynjCDWtEm for ; Fri, 13 Apr 2018 06:03:47 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id E3AF25F3CC for ; Fri, 13 Apr 2018 06:03:46 +0000 (UTC) Received: from moin-vm.apache.org (moin-vm.apache.org [163.172.69.106]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 3EEB4E0117 for ; Fri, 13 Apr 2018 06:03:46 +0000 (UTC) Received: from moin-vm.apache.org (localhost [IPv6:::1]) by moin-vm.apache.org (ASF Mail Server at moin-vm.apache.org) with ESMTP id 914EA80111 for ; Fri, 13 Apr 2018 08:03:45 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Fri, 13 Apr 2018 06:03:45 -0000 Message-ID: <152359942559.23116.16863873810249031942@moin-vm.apache.org> Subject: =?utf-8?q?=5BCouchdb_Wiki=5D_Update_of_=22ActionServerProposal=22_by_Joan?= =?utf-8?q?Touzet?= Auto-Submitted: auto-generated Dear wiki user, You have subscribed to a wiki page "Couchdb Wiki" for change notification. The page "ActionServerProposal" has been deleted by JoanTouzet: https://wiki.apache.org/couchdb/ActionServerProposal?action=3Ddiff&rev1=3D4= &rev2=3D5 Comment: this is show/list ish, and is a cgi-bin approach, and has horrible perf - #redirect Action_server_proposal - This page is an exploration of uses for the plugin API, so that we can ge= t a better feel for the requirements it needs to meet. Most of the features= described here do not exist, at least in the development trunk of CouchDB.= If you are interested in helping with these efforts, please bring it up on= the list or on the IRC channel. = - To read or add other possible use cases for plugins, please see [[PluginA= PIUseCases]]. - = - =3D=3D The Search Interface =3D=3D - = - The _search interface already exists, and forwards any requests to the qu= ery server, which uses a search indexer to find matching documents, and ret= urns them in a JSON structure which is passed back to the requesting client. - = - Example: = - = - A request formed like this - {{{ - http://localhost:5984:/my-db/_search?query=3Dsearch%20string - }}} - appears to the query server as a JSON string: - {{{ - {"db":"my-db","query":"search string"} - }}} - The query server then responds with: - {{{ - {"status":"ok","results":[...]} - }}} - where the results is any array, probably of doc-ids, so the client can fe= tch the documents, but could be an array the documents themselves. The requ= irement is that the _search query server will respond with valid JSON. - = - =3D=3D The Action Interface =3D=3D - = - The _action interface is similar to search, in that it works with an exte= rnal server through the JSON line based protocol. However, the _action serv= er should have the option of returning any string to the requesting client,= not just JSON. One could use the _action interface to serve XML directly f= rom CouchDB. = - = - The _action interface is similar to the _views interface, in that it allo= ws multiple servers in different langauges, and loads the functions to be r= un from CouchDB itself. For instance, a request to _action/mycontroller/mya= ction would load _controllers/mycontroller, and look in it's actions field,= for a subfield called myaction. Myaction is then sent to the action server= to be run with the query params. - = - Example: - = - A request formed like this - {{{ - http://localhost:5984:/my-db/_action/translate/atom?doc=3Dmy-json-feed-do= cument&indent=3D4 - }}} - would load the "translate" controller from /my-db/_controllers/translate = and determine it's language (just like views). Then it would find the appro= priate action server (based on couch.ini) and deliver the request as a JSON= line: - {{{ - {"db":"my-db","action":"function(params, db){var doc =3D db.open(params.d= oc); ...do some E4X magic to make ATOM...; return atom;}","params":{"doc":"= my-json-feed-document","indent":4}} - }}} - The action server then runs the function, and returns the result in an en= velope: - {{{ - {"status":"ok","result":{"body":"...","headers":{"Content-Type":"application/atom+xml"} } } - }}} - CouchDB uses the envelope to set headers, etc, and then serves the body w= ithout wrapping it in JSON. - = - = - =3D=3D=3D What you could do with _action: =3D=3D=3D - = - * Create JSON documents that would ordinarily require multiple requests = against CouchDB to produce. Handy if you have existing API clients that exp= ect a particular format. - * Translate CouchDB's JSON into XML feeds or HTML pages. = - * By using an HTTP proxy to restrict remote client's access to all but t= he _action interface, the _action interface could enforce read and write ac= cess controls, as well as validations. - * Everyone's favorite :) partial updates. = - PUT /my-db/_action/helpers/updatefield?doc=3Dmy-doc-id&field=3Djust-o= ne-field - my doc will have this one field updated. - = - = - =3D=3D=3D Getting there from here: =3D=3D=3D - = - To get these _action and _search working, the first step is standardizing= the JSON line protocol. Currently the view server has a facility for loggi= ng, and sends it's results followed by a single newline. The query server r= equires the results to be in the form {"status":"ok","results":[...]}, foll= owed by two newlines. Making these the same, and adding the ability for the= query server to respond with statuses other than "ok" is the first step. - = - To get _action up and running, a function in the couch_httpd.erl will nee= d to be added that passes the request into the action server (like the _sea= rch interface), and that allows the action server to respond with an envelo= pe containing non-JSON data. Also, in order to support action servers in mu= ltiple langauges, the Erlang side will need to parse the request to find wh= ich controller is being called, load the controller document, and check it'= s language field (defaulting to Javascript) in otder to know which action s= erver to invoke. - = - In order to allow for Action servers in more than one language, couch.ini= would need fields for them, similar to the views. Here is an example couch= .ini. - = - {{{ - = - [Couch View Servers] - = - javascript=3D/usr/local/bin/couchjs /usr/local/share/couchdb/server/main.= js - = - ruby=3D/usr/local/bin/rubyview - = - = - [Couch Search Server] - = - query=3D/Users/jchris/code/couchprojects/query_servers/xapian/couchdb-xap= ian-query - = - update=3D/Users/jchris/code/couchprojects/query_servers/xapian/couchdb-xa= pian-index - = - = - [Couch Action Servers] - = - javascript=3D/usr/local/bin/couchjs /usr/local/share/couchdb/server/actio= n.js - = - ruby=3D/usr/local/bin/rubyaction - = - }}} -=20