CoCreate-api form

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.

Install

npm i @cocreate/api

Or you can use cdn link:

<script>https://cdn.cocreate.app/api/latest/CoCreate-api.min.js</script>

Server run

npm run start

Dependencies components

CoCreate.js, CoCreate-api.js,

Development Guide

1. Directory structure


		|- server
		  |- apis
		     |- {module_name}  //. module directory
		        CoCreate-{module_name}.js
		     |- ...
		     crud.js
		     index.js
		     WSManger.js
		

2. Development stage

(1). Add the module direcotry into server/apis

(2). Create CoCreate-{module}.js from CoCreate-xxx.js template

(3). Register the module in crud.js


		const CoCreateStripe = require('./apis/stripe/Cocreate-stripe')
		module.exports.WSManager = function(manager) {
			new CoCreate.stripe(manager) //. register
		}
		

(4). Rebuild CoCreate-{moudle}.js by endpoint and action


		var utils= require('../utils');
		class CoCreateStripe {
			constructor(wsManager) {
				this.module_id="stripe";
				....
			}
			init() {
				if (this.wsManager) {
					//. endpoint = module_name (ex: stripe)
					this.wsManager.on(this.module_id, (socket, data) = this.sendStripe(socket, data));
				}
			}
			async sendStripe(socket, data) {
		        let type = data['type'];
		        switch (type) {
		            case 'CreateCustomer':  //. action name
		            	... Get result by processing
		                utils.send_response(this.wsManager, socket, {"type":type,"response":result}, this.module_id)
		                break;
		            ....
		        }
			}
		}//end Class 
		module.exports = CoCreateStripe;
		

3. Notes

(1). Response should be object that have type and response

type: action name

response: result

{
			type: action_name,  	//. string
			response: result  		//. object or array
		}
		

(2). Endpoint and moudle_id is same

(3). Send response


		utils.send_response(that.wsManager, socket, {"type":action_name,"response":result}, moudle_id)
		

(4). Request data structure

{
			type: action_name,  	//. string
			data: request_data  	//. object or array
		}
		

How Does It Works

CoCreate-api server module works based on cocreate.api.

xxxxxx action_{action_name}. pre_{action_name}

Effects and Styles

Events

Demo