@cocreate/api
Version:
A simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. CoCreate-api includes the client component and server side for api processing. Thirdparty apis can be accessible using HTML5 attribut
206 lines (172 loc) • 11.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CoCreate-api module Documentation | CoCreateJS </title>
<link rel="icon" type="image/png" sizes="32x32" href="https://cocreate.app/images/favicon.ico">
<meta name="description" content="An api helper component in vanilla javascript to setup thirdparty api intergrations. Apis can be accessible using HTML5 attributes and/or JavaScript API" />
<meta name="keywords" content="drag and drop, colaboration, dnd utility, drag and drop utility" />
<meta name="robots" content="index,follow" />
<meta property="og:image" content="https://cdn.cocreate.app/docs/api.png">
<!-- CoCreate CSS -->
<link rel="stylesheet" href="" type="text/css" />
<link rel="stylesheet" href="/docs/index.css" array="files" object="60888216117c640e7596303f" key="src" type="text/css" save="true" />
<link rel="manifest" href="/manifest.webmanifest">
</head>
<body>
<nav class="nav display:flex align-items:center left:0px background:whitesmoke padding-top:10px padding-bottom:10px" content_id="content" scroll="sticky-nav,hide-nav" scroll-up="10" scroll-down="10" array="files" object="60395ef42b3ac232657040fd" key="src">
</nav>
<sidenav id="menuL" class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl" resizable resize-query="[content_id='content']" resize-property="margin-left" resize-value="width">
<menu array="files" object="603717b07de7fb350ae9fec8" key="src"></menu>
<div resize="right"></div>
</sidenav>
<main class="padding-top:15px padding:15px@lg@xl" content_id="content" id="CoCreate-api-module">
<div class="display:flex flex-wrap:wrap justify-content:space-between position:relative margin:10px">
<div class="display:flex align-items:center">
<h2>CoCreate-api modules</h2>
</div>
<a href="https://github.com/CoCreate-app/CoCreate-dnd" target="_blank" class=""><i src="/assets/svg/github.svg"></i></a>
</div>
<h1 class="max-width:500px margin:20px_10px line-height:1.5 font-size:16px font-weight:100">CoCreate-api is a simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. CoCreate-api includes the
client component and server side for api processing.</h1>
<div id="api-section" class="display:flex flex-wrap:wrap">
<div class="flex-grow:1 width:400px width:300px@xs padding:0px_10px margin-top:60px">
<div id="api-install" class="border-bottom:1px_solid_lightgrey" scroll scroll-intersect="color:dodgerblue" scroll-query="#api-install-section">
<span class="display:flex align-items:center width:fit-content" hover="display:block!important" hover-query="[href='#api-install']">
<h2 class="padding:5px_0px">Install</h2>
<a class="margin-left:10px display:none" href="#api-install"><i src="/assets/svg/link.svg"></i></a>
</span>
</div>
<p class="padding:10px_0px line-height:1.5">
<pre><code class="language-bash">npm i @cocreate/api</code></pre>
</p>
<p class="padding:10px_0px line-height:1.5">Or you can use cdn link:</p>
<pre><code class="language-html"><script>https://cdn.cocreate.app/api/latest/CoCreate-api.min.js</script></code></pre>
<div>
<h2 id="api-dependencies" hover="display:block" hover-query="" class="border-bottom:1px_solid_lightgrey margin-top:80px padding:5px_0px">Dependencies components</h2>
<a class="display:none" href="#api-dependencies"><i src="/assets/svg/link.svg"></i></a>
</div>
<p class="padding:10px_0px line-height:1.5">
<strong>CoCreate.js</strong>,
<strong>CoCreate-api.js</strong>,
</p>
<div>
<h2 id="api-development" hover="display:block" hover-query="" class="border-bottom:1px_solid_lightgrey margin-top:80px padding:5px_0px">Development Guide</h2>
<a class="display:none" href="#api-development"><i src="/assets/svg/link.svg"></i></a>
</div>
<h3 class="margin-top:20px padding:5px_0px">1. Rules</h3>
<h4>(1). Module should be CoCreate-{module_id}.js</h4>
<pre><code class="language-javascript">Ex: CoCreate-stripe.js</code></pre>
<h4>(2). Module should include the actions that has unique name</h4>
<h4>(3). Module id and the endpoint is same.</h4>
<h4>(4). Action function name should be "action_{action_name}"</h4>
<h4>(5). Pre-processing function name should be "pre_{action_name}"</h4>
<h4>(6). Register module</h4>
<pre><code class="language-javascript">Ex: CoCreateApi.register(CoCreateStripe.id, CoCreateStripe);</code></pre>
<p class="padding:10px_0px line-height:1.5">
Stripe modules case's example
<pre><code class="language-javascript">
const CoCreateStripe = {
id: 'stripe', //. module id
actions: [ //. module actions
'CreateCustomer',
'CreateCard',
],
pre_CreateCustomer: function(data) {
console.log(data);
},
action_CreateCard: function(element, data) {
}
}
CoCreateApi.register(CoCreateStripe.id, CoCreateStripe);
</code></pre>
</p>
<h3 class="margin-top:20px padding:5px_0px">2. Cycle Chain</h3>
<h4>(1). When click action button, Run action</h4>
<h4>(2). Run action function.If action function defined in module, the action function (action_{action_name}) call.</h4>
<div class="padding-left:1rem">
<p>(2)-1. If action function defined in module, the action function (action_{action_name}) call.</p>
<p>(2)-2. If action funciton undefined in module, the common action function call.</p>
<div class="padding-left:1rem">
<p> - Get the dat from form</p>
<p> - Send the data and action by endpoint into server</p>
</div>
</div>
<h4>(3). Server Processing.</h4>
<h4>(4). Received the response from server.</h4>
<h4>(5). If pre-processing function defined in module, the pre-processing function (pre_{action_name}) call.</h4>
<h4>(6). Call the render function by action .</h4>
<h4>(7). Fire the event for end (event name is {action_name})</h4>
<h4>(8). Run the next action by cocreate-action</h4>
<h3 class="margin-top:20px padding:5px_0px">3. Description</h3>
<h4>Action function</h4>
<pre><code class="language-javascript">
---------------------Module-----------------
// element: Node to define action
// data: data to receive from previous action
function action_{action_name}(element, data)
--------------------HTML------------------------
<button actions="{action_name}, {action_name1}, ...">Run</button>
Example:
action_CreateCard: function(element, data) {}
<button actions="CreateCustomer, CreateCard">Run</button>
</code></pre>
<h4>Pre-processing function</h4>
<pre><code class="language-javascript">
// data: response data from server
function pre_{action_name}(data)
Example:
pre_CreateCard: function(data) {
localstorage['card'] = data['response'];
} </code></pre>
<h4 class="margin-top:20px padding:5px_0px">Server response</h4>
<pre><code class="language-javascript">{
type: "{action_name}",
response: {...}
}</code></pre>
<h2 class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">How Does It Works</h2>
<p>CoCreate-api module works based on cocreate.api. </p>
<p>xxxxxx <code class="language-js">action_{action_name}</code>. <code class="language-js">pre_{action_name}</code></p>
<h2 class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">Effects and Styles</h2>
<h2 class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">Events</h2>
<h4><span></span><span class="cocreate-badge success"></span></h4>
</div>
<div class="flex-grow:1 width:300px padding:0px_10px margin-top:60px border-bottom:1px_solid_lightgrey">
<!-- SandBox -->
<div id="api-demo" class="border-bottom:1px_solid_lightgrey" scroll scroll-intersect="color:dodgerblue" scroll-query="#api-demo-section">
<span class="display:flex align-items:center width:fit-content" hover="display:block!important" hover-query="[href='#api-demo']">
<h2 class="padding:5px_0px">Demo</h2>
<a class="margin-left:10px display:none" href="#api-demo"><i src="/assets/svg/link.svg"></i></a>
</span>
</div>
<div class="position:sticky top:0 padding:15px_0px height:100vh">
<!-- SandBox -->
<div class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px" id="playground">
<div id="demo-code" resizable class="position:relative height:50%">
<textarea type="code" lang="html" array="demos" object="" key="demo" save="false" id="demo" class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
<div resize="bottom" class="background:lightgrey"></div>
</div>
<div id="demo-preview" class="position:relative overflow:auto background-color:white">
<div class="demopreview padding:20px"></div>
</div>
<div class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
<a class="margin-right:10px" id="eye" show="#eye-slash" hide="#eye, #demo-preview" toggle="code-height" toggle-query="#demo-code"><i class="height:18px" src="/assets/svg/eye.svg"></i></a>
<a class="margin-right:10px" hidden id="eye-slash" show="#eye, #demo-preview" hide="#eye-slash" toggle="code-height" toggle-query="#demo-code"><i src="/assets/svg/eye-slash.svg"></i></a>
<a class="margin-right:10px" id="code" show="#code-slash" hide="#code, #demo-code"><i src="/assets/svg/code.svg"></i></a>
<a class="margin-right:10px" hidden id="code-slash" show="#code, #demo-code" hide="#code-slash"><i class="height:18px" src="/assets/svg/code.svg"></i></a>
<a class="margin-right:5px" fullscreen fullscreen-query="#playground"></a>
</div>
</div>
<!-- End SandBox -->
</div>
</div>
</div>
<button href="https://github.com/CoCreate-app/CoCreate-api/tree/master/docs/index.html?message=docs%3A%20describe%20your%20change..." target="_blank" class="position:fixed bottom:15px right:15px padding:15px background:dodgerblue color:#fff font-size:1.5rem grow-hover border-radius:50% border-width:0 box-shadow:0px_2px_10px_0px_rgba(0,_0,_0,_0.4)">
<i src="/assets/svg/pencil-alt.svg"></i>
</button>
</main>
<script src="https://CoCreate.app/dist/CoCreate.js"></script>
</body>
</html>