{"version": "2.0","name": "RAPID ","subline": "API RESTful server for PostgreSQL","username": "Q-Bis Consult S.R.L.","created": "09/04/2015","website": "http://www.qbis.ro","update": "10/07/2015","update_today": true,"email": "support@qbis.ro","description": "A RESTful API for PostgreSQL databases.\nCRUD operations and more","intro": "Automate all CRUD operations for your PostgreSQL databases.","button_1_text": "Support","button_2_text": "","button_3_text": "","button_1_url": "http://www.nedcosafe.com","button_2_url": "","button_3_url": "","sections": [{"title": "Features overview","id": "features_overview","content": "<h2>\n\t<strong>RESTful API server features</strong></h2>\n<p>\t<strong><img alt=\"\" src=\"http://www.nedcosafe.com/pict/app.png\" style=\"width: 500px; height: 330px;\"></strong></p>\n<p>\tImplements all CRUD operations (CREATE, READ, UPDATE, DELETE).<br>\n\tAutomatically imports the database structure and create a metadata of your database.Single point access, accept POST/PUT/GET/DELETE http methods and respond with a JSON data object.</p>\n<p>\tBasic operations can be used from the start:</p>\n<ul>\t<li>\t\tCREATE - insert records</li>\n\t<li>\t\tREAD - read one record by ID</li>\n\t<li>\t\tUPDATE - update one record</li>\n\t<li>\t\tDELETE - delete one record</li>\n</ul>\n<p>\tThe servers accepts batch of different commands at once and uses transactions by default.</p>\n<p>\tInject your code BEFORE and AFTER operations in order to customize access to each action.</p>\n<p>\tCreate queries and access them with simple GET commands.</p>\n<p>\tCurrent version can be set to access data from one PostgreSQL server. If you need to access different PostgreSQL servers from a single point please check the enterprise version availability with support team at support@nedcosafe.com.</p>\n<p>\tThis RESTful API server can be used to offer WEB services for various kind of applications and devices over HTTP/HTTPS protocol like WEB, mobile or IoT applications&nbsp; that consumes WEB services.</p>\n<p>\tOne solution can scale by adding new API servers, the configuration can be shared within instances. To scale the solution a Load Balancing server is required and next just add or drop API instances to it.</p>\n"},{"title": "About","id": "about","content": "<p>\t<br>\n\t<strong>License</strong></p>\n<div class=\"content clearfix\">\n\t<div class=\"field field-name-body field-type-text-with-summary field-label-hidden\">\n\t\t<div class=\"field-items\">\n\t\t\t<div class=\"field-item even\">\n\t\t\t\t<p>\t\t\t\t\tThe MIT License (MIT)</p>\n\t\t\t\t<p>\t\t\t\t\tCopyright (c) 2015 Q-Bis Consult S.R.L.</p>\n\t\t\t\t<p>\t\t\t\t\tPermission is hereby granted, free of charge, to any person obtaining a copy<br>\n\t\t\t\t\tof this software and associated documentation files (the &quot;Software&quot;), to deal<br>\n\t\t\t\t\tin the Software without restriction, including without limitation the rights<br>\n\t\t\t\t\tto use, copy, modify, merge, publish, distribute, sub-license, and/or sell<br>\n\t\t\t\t\tcopies of the Software, and to permit persons to whom the Software is<br>\n\t\t\t\t\tfurnished to do so, subject to the following conditions:</p>\n\t\t\t\t<p>\t\t\t\t\tThe above copyright notice and this permission notice shall be included in<br>\n\t\t\t\t\tall copies or substantial portions of the Software.</p>\n\t\t\t\t<p>\t\t\t\t\tTHE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>\n\t\t\t\t\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>\n\t\t\t\t\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>\n\t\t\t\t\tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>\n\t\t\t\t\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>\n\t\t\t\t\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>\n\t\t\t\t\tTHE SOFTWARE.</p>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>\n<p>\t<strong>About</strong></p>\n<p>\tDeveloped and maintained by:</p>\n<p>\tQ-Bis Consult S.R.L.<br>\n\t<a href=\"http://www.qbis.ro\" target=\"_blank\">www.qbis.ro</a><br>\n\tsupport@qbis.ro</p>\n<p>\tNEDCO SAFE S.R.L.<br>\n\t<a href=\"http://www.nedcosafe.com\" target=\"_blank\">www.nedcosafe.com</a><br>\n\tsupport@nedcosafe.com</p>\n<p>\tDANCO S.R.L.<br>\n\t<a href=\"http://www.dancosolutions.net/\">http://www.dancosolutions.net/</a><br>\n\toffice@dancosolutions.net</p>\n<p>\t&nbsp;</p>\n<p>\t<strong>Dependency</strong></p>\n<p>\tRAPID API is a NodeJS application based on Express server framework. It uses next modules:</p>\n<div class=\"alert alert-info\">\n\texpress, cors, pg, pg-spice, jsonwebtoken, pem, redis, skipper,buffer-crc32, debug,</div>\n"},{"title": "Installation","id": "installation","content": "<p>\t<strong>RESTful API for PostgreSQL</strong></p>\n<p>\tRequirements:</p>\n<p>\t- OpenSSL shuld be installed before in order to allow the server to create it&#39;s first self-signed SSL certificate.<br>\n\t- for Linux you will need to set your computer to accept Node opening lower ports (80/443 ...) without root access, next code works for Ubuntu</p>\n<p>\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sudo apt-get install libcap2-bin<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sudo setcap cap_net_bind_service=+ep /usr/local/bin/node</p>\n<p>\tUnzip the server archive.</p>\n<div class=\"alert\">\n\tRun this inside the new server folder:&nbsp;&nbsp;&nbsp;</div>\n<div class=\"alert alert-info\">\n\tsudo npm install</div>\n<p>\tRun the server with:</p>\n<div class=\"alert alert-info\">\n\tnode start.js</div>\n<p>\t<strong>The server can be managed at:&nbsp; https://&lt;server Ip or domain name&gt;<br>\n\tIt will generate a self-signed SSL certificate at start until you will provide an authorized one.</strong></p>\n<p>\tIf OpenSSL can not be found, you may need to provide a SSL certificate otherwise the server will not start.<br>\n\tPut the certificate into &quot;ssl&quot; folder as service.crt and service.key files. The SSL certificate is a PEM encoded crt file.<br>\n\t<br>\n\tYou can change the server port and protocol (HTTP/HTTPS) for API access from settings page.</p>\n<p>\tPlease check the SSL documentation page for more information.</p>\n<p>\tSee SETTINGS chapter for this server SSL setup after installation.</p>\n<p>\t&nbsp;</p>\n"},{"title": "Start page","id": "start_page","content": "<p>\tServer information page.</p>\n<p>\tThis page will display server status or required actions to setup the server.</p>\n<p>\t<img alt=\"StartPage\" src=\"http://www.nedcosafe.com/pict/startpage.png\" style=\"width: 300px; height: 305px;\"></p>\n"},{"title": "Settings","id": "settings","content": "<p>\tApplication server setup starts here.</p>\n<p>\tBe sure that you can access your PostgreSQL database server by setting your firewalls and security rules to alow access from the application server computer/vpc. For Amazon RDS you will need to setup properly your database security group.</p>\n<p>\tFirst action that comes with a fresh new server is to set its data access information. It is a short wizard that ask for your database connection credits. If the database is not found or can not be reached an error message is displayed.e</p>\n<p>\t<strong>Database server:</strong></p>\n<p>\tIn order to set access to a PostgreSQL server next information are required:</p>\n<ul>\t<li>\t\tserver address (IP or domain name)</li>\n\t<li>\t\tport (standard is 5433 or 5334 for RDS)</li>\n\t<li>\t\tdatabase (a database on the server)</li>\n\t<li>\t\tuser (one user that have rights to access and create databases on the server)</li>\n\t<li>\t\tpassword (...)</li>\n</ul>\n<p>\tWhen used with Amazon RDS there are settings to be made on AWS console related to access security. Please check the AWS documentation.</p>\n<p>\tAll database server REST API configuration is stored in a database on the used PostgreSQL server (rcfg). By storing nothing important locally the system can scale simple adding new servers.</p>\n<p>\tFrom settings page you can change administrator password or set an address for another PostgreSQL server.</p>\n<p>\t<strong>System:</strong></p>\n<p>\tAdministrator - set the administrator name and password</p>\n<p>\tRAPID API - control the RESful API server (set properties, start /stop).</p>\n<p>\tTOKEN password - used for API authorization by default. The authorization method can be changed into RULES page at choice, code for JWT authorization is provided and samples for basic authorization.</p>\n<p>\tSSL Certificate - set/view the used SSL certificate.</p>\n<p>\tAfter some changes the server is restarted automatically to apply changes that require restart (SSL, port ...)</p>\n"},{"title": "Security","id": "security","content": "<p>\tSecurity is one of most concerns in today world, dealing with databases over WEB is a potential security risk that need attention from the very start of your WEB application project.</p>\n<p>\tRAPID servers uses HTTPS protocol for data communication and flexible authorization methods implementing JWT by default.</p>\n<p>\tAuthorization is based on &quot;Authorization&quot; header provided with each request, the server is a RESTful server and does not stores any user session. It is advised to use JWT for API access, however the authorization method can be changed to any of your choice by modifying the AUTHORIZATION js file (rpdauth.js) using RULES page.</p>\n<p>\tOne SSL self-signed certificate is created when the server is started first time, it can be changed at any time using settings page.</p>\n<p>\tADMIN interface has one administrator only and it is protected by a basic authorization, in plus an IP filter list can be set to allow access to ADMIN module only from particular locations.</p>\n<p>\tThe server will open two ports, one for administration witch is 443 and 3330 for API access. It is recommended to use another port than 443 for API access as 443 port is generally more exposed to benign crawlers or malicious random attack. Change API port in settings page.</p>\n<p>\tUse &quot;IP filtering&quot; in settings page to protect better the ADMIN interface.</p>\n"},{"title": "SSL","id": "ssl","content": "<p>\t<a href=\"https://en.wikipedia.org/wiki/Transport_Layer_Security\">https://en.wikipedia.org/wiki/Transport_Layer_Security</a></p>\n<p>\tFor a good security compliance in a production environment and to be sure that your REST API server will be accepted by all clients you will need to set a certified SSL certificate issued by an authorized CA (Certificate Authority).</p>\n<p>\tSSL certificates can be issued for an IP or a Domain name, depending on your requirements you may chose from different CA providers.</p>\n<p>\tOpenSSL can be used to create self signed SSL certificates or certificate requests. See next article for details.<br>\n\t<a href=\"https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs\">https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs</a></p>\n<p>\tAt start the server will create automatically a self signed certificate to protect the administration pages. This certificate can be used safely at start as it is unique and good enough to protect most sensitive information.</p>\n<p>\tIn &quot;development&quot; mode, the REST API server can be used with HTTP unprotected protocol, however when the server is set in &quot;production&quot; mode a verified certificate is needed, otherwise the server can not be used as a cross origin resource for WEB applications and mobile applications based on WEBkit.</p>\n<p>\tSSL certificate can be set in SETTINGS page. There will be needed a PEM encoded CRT file and it&#39;s private key. The private KEY should have no password protection.<br>\n\t&nbsp;</p>\n"},{"title": "Authorization","id": "authorization","content": "<p>\tRAPID server is a RESTful API server, it can be set to accept any kind of authorization method by allowing custom code.</p>\n<p>\tSince the server can be used in a SOA infrastructure the best option for authorization is token based.</p>\n<p>\tRAPID API exposes by default&nbsp; a JSON WEB TOKEN authorization method.<br>\n\thttps://github.com/auth0/node-jsonwebtoken</p>\n<p>\t<strong>JWT authorization</strong></p>\n<p>\tTo set up properly the system you will need to change the default JWT private key to the same key of your applications that uses this API server (the token emitter).</p>\n<p>\tToken required by RAPID is at least &quot;user&quot;, the JWT can contain a lot of other information you may need for your application.</p>\n<p>\tThe &quot;user&quot; information can be used further in your RULES code for different purposes. If you will not need to differentiate your users access you may use same token for all interfaces regardless who uses the application.</p>\n<p>\tDevelopment tokens can be created in TOKENS page, (new tab/tokens).</p>\n<p>\tWhy JWT?</p>\n<p>\tIn a RESTful world each request is not related to any previous one, the server does not stores any user related information, on the other hand when used as an API provider one server may be not the same as the WEB application server so cookies can not be used properly, the solution is to provide an authorization code for each request. If authorization need to be confirmed with another service that will cost processing power. JWT solve this by checking the authorization token server side based on same settings as the token emitter. Using it along with HTTPS this is a safe standard industry authorization method.</p>\n<p>\tTokens are accepted as authorization headers or query parameter. However that can be changed in AUTHORIZATION rules (javascript code).</p>\n<div class=\"alert alert-info\">\n\tAuthorization: Bearer XAIHAUIAHUIAHUUIAUYIAYJAKIHAUIHAIUHDUIHAIDUUIVAHDGUSGYU</div>\n<p>\tor</p>\n<div class=\"alert alert-info\">\n\ttoken=XAIHAUIAHUIAHUUIAUYIAYJAKIHAUIHAIUHDUIHAIDUUIVAHDGUSGYU in a HTTPs query request</div>\n<div class=\"alert alert-info\">\n\tlike https://myserver/rapid/&lt;mycommand&gt;?token=mytoken</div>\n<p>\t<strong>BASIC authorization</strong></p>\n<p>\tA basic authorization is based on an authorization header:</p>\n<p>\tAuthorization: Basic &lt;base 64 code (user:pass)&gt;</p>\n<p>\tIt is safe when used with HTTPS, but still the username and password need to be checked against a database.</p>\n<p>\tAny authorization like OAUTH2.0 or third-party from Facebook or other providers can be implemented by changing the AUTHORIZATION rule with your own custom Javascript code.</p>\n"},{"title": "JSON WEB TOKENS (JWT)","id": "json_web_tokens_jwt","content": "<p>\tJSON WEB TOKENS or JWT</p>\n<p>\tA standard authorization method for WEB API&#39;s.<br>\n\tIt uses the WEB request Authorization header to provide the token.</p>\n<div class=\"alert alert-success\">\n\tAuthorization: Bearer JHUIHYUIBYTUIYUITU.ITVRTUIYIUT...</div>\n<p>\tOne token is an encrypted JSON. The emiter (authorization server) should have the same private key with the API service server, one that will check the token validity.</p>\n<p>\tTokens can have any required attributes, like USER, EMAIL, ID&#39;s, EXPIRE.</p>\n<div class=\"alert alert-success\">\n\t{<br>\n\t&nbsp;&nbsp; &quot;user&quot;:&quot;test201&quot;,<br>\n\t&nbsp;&nbsp; &quot;email&quot;:&quot;test201@mydomain.com&quot;,<br>\n\t&nbsp;&nbsp; &quot;expire&quot;: 12242094494,<br>\n\t&nbsp;&nbsp; ...<br>\n\t}</div>\n<p>\tRAPID API server implements authorization by checking each request with the rpdauth.js auth function (see AUTHORIZATION page). The JWT Authorization token is decrypted and added to the client request as it is. By simple decrypting the token, the authorization is passed. Later any other rule can check the decrypted token object properties for application purposes like access rights, logs and any needed.</p>\n<p>\tIn BEFORE RULES can be used like:</p>\n<div class=\"alert alert-success\">\n\t...<br>\n\tmytableCreate:function(req,atr,next){ // CREATE rule for mytable<br>\n\t&nbsp;&nbsp;&nbsp; var user&nbsp;&nbsp;&nbsp; = req.token.user;&nbsp;&nbsp; // get the username to be used<br>\n\t&nbsp;&nbsp;&nbsp; ...<br>\n\t&nbsp;&nbsp;&nbsp; atr.userid = req.token.userid;&nbsp; // set an userid atribute to be inserted into table<br>\n\t&nbsp;&nbsp;&nbsp; next();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // calback to main function when ready<br>\n\t},<br>\n\t...</div>\n<pre class=\"plain\">\n</pre>\n<p>\t&quot;checkAll&quot; BEFORE rule can be used to check if token is expired. This will apply to all requests.</p>\n<div class=\"alert alert-success\">\n\t...<br>\n\tcheckAll:function(req,atr,next){<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp; if (!req.token.expire){return next()}<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp; if (req.token.expire &lt; new Date()){return next({error:&quot;expired token&quot;})}<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp; return next();<br>\n\t}<br>\n\t...</div>\n"},{"title": "CORS","id": "cors","content": "<p>\tCross Origin Resource Sharring&nbsp; a default standard for a Service Oriented Arhitecture.</p>\n<p>\tRAPID API is CORS enabled by default.</p>\n<p>\tMore detail related to CORS can be found at <a href=\"https://en.wikipedia.org/wiki/Cross-origin_resource_sharing\">https://en.wikipedia.org/wiki/Cross-origin_resource_sharing</a>.</p>\n<p>\tAn API server used as a cross origin resource always should use an <strong>verified SSL certificate</strong>, otherwise the client web browser will not accept the connection at fist place.</p>\n<p>\tIt is not reccomended to open and use a REST API server without encryption (HTTPS protocol).</p>\n<p>\t&nbsp;</p>\n"},{"title": "API - CRUD operations","id": "api_crud_operations","content": "<p>\t<strong>API</strong></p>\n<p>\tCreate, Read, Update, Delete or CRUD refers to basic operations on databases, in plus there are options to query the database and run a batch of operations at once in a transaction.</p>\n<p>\tThe server do not accept free SQL&#39;s via REST API as this can be a security issue, instead each SQL you may need should be declared as SQL statement and used via a REST command. The server uses JSON data format for requests and responses. Next are described HTTP commands that can be used with the REST API server.</p>\n<p>\tAll CRUD operations are ready to be used without additional settings after server configuration, however if you will need more it can be done with rules for each operation and table in your databases (before and after rules).</p>\n<p>\tAll requests should provide next headers, one token can be set using TOKENS page, please check JSON WEB Tokens page. Authorization method can be changed.</p>\n<div class=\"alert alert-info\">\n\tAuthorization:Bearer JAKHDHUBUDYUDYBUIDYBNOOIIUSDO ...<br>\n\tContent-Type:application/json; charset=utf-8<br>\n\t&nbsp;</div>\n<p>\tserver_address: your server address including port like myserver.com:3330</p>\n<p>\t<strong>CREATE</strong></p>\n<p>\tInsert a new record.</p>\n<p>\tRequest:</p>\n<ul>\t<li>\t\tmethod: POST</li>\n\t<li>\t\tdata: req.body, accept JSON &ndash; one table row</li>\n\t<li>\t\tpath: <code>&lt;server address&gt;/rapid/&lt;table&gt;</code></li>\n</ul>\n<p>\tRAPID will add the primary key if not sent in request, the primary key is a standard GUID of &hellip; characters. RAPID check that each field in request belong to the table and each mandatory field in the table it is in the request (exception the PK that can be created if missing). After compliance the request is prepared and sent to the RDBMS as INSERT statement.</p>\n<p>\tSample CREATE (POST) request:</p>\n<p>\tPath:</p>\n<pre class=\"prettyprint prettyprinted\" style=\"\">\n<code><span class=\"pln\">http</span><span class=\"pun\">:</span><span class=\"com\">//testserver.com/rapid/users</span></code></pre>\n<p>\tRequest body:</p>\n<pre class=\"prettyprint prettyprinted\" style=\"\">\n<code><span class=\"pun\">{</span><span class=\"str\">&quot;username&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;test1&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;firstname&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;John&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;lastname&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;Smith&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;email&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;someone@aol.com&quot;</span><span class=\"pun\">}</span></code></pre>\n<p>\t<strong>READ</strong></p>\n<p>\tRead a record by primary key.</p>\n<p>\tFIND : Check for one record, it is enabled by default and no further actions are required to make it working.</p>\n<p>\tQUERY : To return more data from the same table or from more tables, it needs preparations in form of a SQL statement saved into SQLS configuration table.</p>\n<p>\t<strong>FIND</strong></p>\n<p>\tRAPID uses this to check if a record exist and return its data.</p>\n<p>\tRequest:</p>\n<ul>\t<li>\t\tmethod: GET</li>\n\t<li>\t\tdata: req.query, parameters</li>\n\t<li>\t\tpath: <code>&lt;server address&gt;/rapid/&lt;table&gt;?&lt;PK&gt;=&lt;key value&gt;</code></li>\n</ul>\n<p>\tThe response is the entire row in JSON format. If you will need to control further the response in order to not return some fields just set your rules into rpdafter.js for yourtableFind (SailsJs/js/rpdafter.js).</p>\n<p>\tWithout parameters (pky) will return a maximum of 1000 unsorted records from the table.</p>\n<p>\t<strong>UPDATE</strong></p>\n<p>\tSame as CREATE, exceptions are:</p>\n<ul>\t<li>\t\tprimary key should exist into request</li>\n\t<li>\t\trequest method is PUT</li>\n</ul>\n<p>\tReturns JSON</p>\n<p>\t<strong>DELETE</strong></p>\n<p>\tRequest:</p>\n<ul>\t<li>\t\tmethod: DELETE</li>\n\t<li>\t\tdata: req.query, parameter</li>\n\t<li>\t\tpath: <code>&lt;server address&gt;/rapid/&lt;table&gt;?&lt;PK&gt;=&lt;key value&gt;</code></li>\n</ul>\n<p>\tCan be used to mark a record as deleted instead really delete. To do that you need to have one boolean field named &lsquo;deleted&rsquo; into the table. (<em>Please set your SQL Queries accordingly if you are using &lsquo;deleted&rsquo; field mark</em>)</p>\n<p>\tThe response is a JSON with DELETE command result not the deleted row. Functions for before and after actions can be set into rpdafter.js and rpdbefore.js (see next chapters for details)</p>\n<p>\t<strong>QUERY</strong></p>\n<p>\tAllows you to run a SQL statement and return the response as JSON.<br>\n\tQueries can be set using the application &quot;Queries&quot; option from a new tab. Check also in page help.</p>\n<p>\tSample SQL:</p>\n<p>\tRAPID uses &lsquo;&amp;&rsquo; wild-card here to mark a parameter, this conventions comes back from ODBC or ADO queries standard. The SQL statement should respect the RDBMS standards and syntax.</p>\n<pre class=\"prettyprint prettyprinted\" style=\"\">\n<code><span class=\"kwd\">select</span><span class=\"pln\"> users</span><span class=\"pun\">.</span><span class=\"pln\">firstname</span><span class=\"pun\">,</span><span class=\"pln\"> users</span><span class=\"pun\">.</span><span class=\"pln\">lastname</span><span class=\"pun\">,</span><span class=\"pln\"> users</span><span class=\"pun\">.</span><span class=\"pln\">email</span><span class=\"pun\">,</span><span class=\"pln\">\nassets</span><span class=\"pun\">.</span><span class=\"pln\">assetname</span><span class=\"pun\">,</span><span class=\"pln\">assets</span><span class=\"pun\">.</span><span class=\"pln\">description\n</span><span class=\"kwd\">from</span><span class=\"pln\"> assets inner join users on assets</span><span class=\"pun\">.</span><span class=\"pln\">uid </span><span class=\"pun\">=</span><span class=\"pln\"> users</span><span class=\"pun\">.</span><span class=\"pln\">id\norder </span><span class=\"kwd\">by</span><span class=\"pln\"> users</span><span class=\"pun\">.</span><span class=\"pln\">firstname\n</span><span class=\"kwd\">where</span><span class=\"pln\"> assets</span><span class=\"pun\">.</span><span class=\"pln\">catid </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"pun\">&amp;</span><span class=\"pln\">selcatid</span></code></pre>\n<p>\tRequest:</p>\n<ul>\t<li>\t\tmethod: GET</li>\n\t<li>\t\tpath: <code>&lt;server address&gt;/rapid/rpdquery?csql=&lt;sqlname&gt;&amp;&lt;par1&gt;=&lt;val1&gt;&amp;&lt;par2&gt;=&lt;val2&gt; ...</code></li>\n</ul>\n<p>\tRestrictions:</p>\n<ul>\t<li>\t\tsqlname should exist as request parameter</li>\n\t<li>\t\tRAPID will check that all QUERY parameters exist into the request.</li>\n\t<li>\t\ttwo additional paramters are required: <em>limit</em> and <em>offset</em>, both are integers and are used for result pagination.</li>\n</ul>\n<p>\tSample request:</p>\n<pre class=\"prettyprint prettyprinted\" style=\"\">\n<code><span class=\"pln\">http</span><span class=\"pun\">:</span><span class=\"com\">//54.69.200.49:1337/rapid/rpdquery?csql=test&amp;limit=50&amp;offset=0</span></code></pre>\n<p>\tThe result is in JSON format.</p>\n<p>\tQueries</p>\n<p>\tImplemented CRUD operations offers data access by default. An API server <strong>should not</strong> accept SQL requests from the client as it is not secure enough.</p>\n<p>\tRAPID solves this by storing server side SQL statements that can be later accessed.</p>\n<p>\tUse QUERIES page to manage queries list (write/test SQL&#39;s). Results are always sent in JSON format.</p>\n<p>\t&nbsp;</p>\n<div class=\"alert alert-success\">\n\tThe REST command for the service is:<br>\n\t<code>https://yourserveraddress:port/rapid/rpdquery?csql=nameofthesql&amp;[par1=val1&amp;par2=val2] ...&amp;limit=0&amp;offset=0 </code><br>\n\t<br>\n\tlimit = number of returned records (0 defaults to 1000/ 10 records for test)<br>\n\toffset = number of records set to return (pagination)</div>\n<p>\tSample front-end Angular request object:</p>\n<div class=\"alert alert-success\">\n\tvar req = {<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method: &quot;GET&quot;,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: &quot;https://yourserveraddress:port/rapid/rpdquery&quot;,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; headers:{<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Content-Type: &quot;application/json; charset=utf-8&quot;,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Authorization:&quot;Bearer JHJAHDBAUDIYIU ....&quot;<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; params:{<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; csql:&quot;nameoftheSQL&quot;,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; limit:0,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; offset:0,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par1:&quot;par1&quot;,<br>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par2:&quot;par2&quot;,<br>\n\t&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>\n\t&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\n\t}</div>\n<p>\t&nbsp;</p>\n<p>\t<strong>CRUD batch operations</strong></p>\n<p>\tRAPID can be used to save (create,update,delete) more records from different tables even from different databases using one request. It can use two methods for its purpose, one that opens a transaction per database and the second one that threat each dataset row as an individual request and returns errors in case as a separate object into the response.</p>\n<p>\tRequest:</p>\n<ul>\t<li>\t\tmethod: POST</li>\n\t<li>\t\tdata: req.body</li>\n\t<li>\t\tpath : <code>&lt;server address&gt;/rapid/up_data</code></li>\n\t<li>\t\tpath (transactional) : <code>&lt;server address&gt;/rapid/up_tdata</code></li>\n</ul>\n<p>\tRequest body (JSON):</p>\n<p>\tAn object &ldquo;data&rdquo; of tables where each table is an array of row objects. Each row should have a property rpdstatus = -1,0,1,2</p>\n<ul>\t<li>\t\t-1 = delete</li>\n\t<li>\t\t0 = do nothing</li>\n\t<li>\t\t1 = create</li>\n\t<li>\t\t2 = update</li>\n</ul>\n<p>\tAdd as many tables and row records as your system can load. It is useful to save documents like invoices, orders and any alike in one shot. This approach where widely used by traditional client server desktop applications.</p>\n<p>\tSample:</p>\n<pre class=\"prettyprint prettyprinted\" style=\"\">\n<code><span class=\"pun\">{</span><span class=\"str\">&quot;data&quot;</span><span class=\"pun\">:{</span><span class=\"str\">&quot;attach&quot;</span><span class=\"pun\">:[\n            {</span><span class=\"str\">&quot;id&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;a123&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;file&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;max1&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;type&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;txt&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;rpdstatus&quot;</span><span class=\"pun\">:</span><span class=\"lit\">1</span><span class=\"pun\">},\n            {</span><span class=\"str\">&quot;id&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;b123&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;file&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;max2&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;type&quot;</span><span class=\"pun\">:</span><span class=\"str\">&quot;txt&quot;</span><span class=\"pun\">,</span><span class=\"str\">&quot;rpdstatus&quot;</span><span class=\"pun\">:</span><span class=\"lit\">2</span><span class=\"pun\">}\n            ]\n        }\n}</span></code></pre>\n<p>\tResponse:</p>\n<p>\tA JSON almost identical with the request, rpdstatus will be set to 0 for solved records and 9 if an error where encountered (up_data path), for each error a descriptive row is added to the response dataset. If the request was sent to be transactional (up_tdata path) in case of any error the error is returned and the traqnsaction is rooled back, these hapens even we are using tables from more than one database within the same dataset.</p>\n"},{"title": "Sample testing","id": "sample_testing","content": "<p>\tWe recommend Firefox and Firefox RestClient for direct testing.</p>\n<p>\tNext image present an Create request with Firefox RestClient:</p>\n<p>\tCREATE uses POST method and a JSON key values object parameters body of fields and values to insert.<br>\n\tYou will need a token in order to set properly the authorization header (use Headers and Authorization / token). Headers can be saved for later use, same for requests.</p>\n<p>\tCreate will return created record as OK result. Useful when you do not send an ID rather retrieve one from the server.<br>\n\tThe server always add an unique UUID if one is not provided.</p>\n<p>\t<br>\n\t<img alt=\"\" src=\"http://www.nedcosafe.com/pict/sample.png\" style=\"width: 450px; height: 363px;\"></p>\n<p>\t&nbsp;</p>\n"},{"title": "Rules (before & after)","id": "rules_before_after","content": "<p>\tRULES for CRUD operations</p>\n<p>\tRules editor offers javascript syntax checkings and final validation before overwrite one of the server js files.</p>\n<p>\t<strong>Before rules </strong>refers to functions that can be set to run before an CRUD operation of RESTful API.<br>\n\tCRUD operations are based on client REQUEST, depending on the request type there each request comes with parameters or attributes. Before rules are in place to check or alter the request parameters to provide a better option for your application API.</p>\n<p>\tBefore rules are implemented as module from &quot;rpdbefore.js&quot; file found on &quot;js&quot; folder of your server root. When is edited it is copied to &quot;js/work&quot; folder and saved only after it is checked against gross errors that can stop the start process of your server.</p>\n<p>\tFunction naming rule is simple, the function name is formed by table name (lowercase) and action name proper case (Create, Find, Update, Delete).</p>\n<p>\tFunction parameters:</p>\n<ul>\t<li>\t\treq&nbsp;&nbsp; - express client request, provides all needed information related to client request</li>\n\t<li>\t\tatr&nbsp;&nbsp;&nbsp; - object atributes, request parameters sent in body or query, it is an key/value object.</li>\n\t<li>\t\tnext - the callback function, it should be used otherwise the service will never respond, if should stop the service it can be used to return an error by giving a parameter like <em>next(my_error)</em></li>\n</ul>\n<p>\tSample:</p>\n<pre>\nmodule.export = {\n  \t\t...\n\t  \tusersCreate: function(req,atr,next){\n\t  \t\tatr.id = myfunction(); // create custom ID\n\t  \t\tif (!atr.email){return next({error:&quot;email required&quot;});\n\t  \t\tnext()\n\t  \t},\n  \t\t...\n  \t}</pre>\n<p>\tThe <strong>checkAll</strong> before rule runs on top of all requests if it is set (found in module).</p>\n<p>\t<strong>After rules </strong>refers to functions that can be set to run after a CRUD application of RESTful API. It is useful to check and change the request result. Same model as &quot;BEFORE&quot; rules.</p>\n<p>\t&nbsp;</p>\n<p>\t&nbsp;</p>\n"}],"use_sub": false,"logo": "","favicon": "","customcss": "","easing": "swing","easingduration": "100","bgimage": "","bgrepeat": "repeat","bgattachment": "scroll","bgcolor": "FFFFFF","textcolor": "383838","linkcolor": "0000FF","hrcolor1": "D3EFF0","hrcolor2": "FFFFFF","btncolor": "FFFFFF","btncolor1": "0088CC","btncolor2": "0044CC","sidebarbgimage": "","sidebarbgrepeat": "repeat","sidebarbgcolor": "DDDDDD","sidebartextcolor": "222222","sidebarlinkcolor": "444444","sidebaractivecolor": "444444","sidebaractivetextcolor": "DDDDDD","sidebarhrcolor1": "AAAAAA","sidebarhrcolor2": "EEEEEE","cufon": "","documentationttype": "default","itemURL": "","sendJSON": "","sendZIP": "","sendPWD": ""}
