askless-javascript-client v1.0.1
Askless - JavaScript client
:checkered_flag: Português (Portuguese)
JavaScript client of Askless framework, which facilitates building servers for JavaScript and Flutter Apps allowing to:
:handshake: perform a websocket connection to exchange data that:
:vibration_mode: supports streams on the client side in Flutter
:computer: supports JavaScript clients: Web and Node.js
:arrow_right_hook: automatically retry sending data in case of connectivity issues between the client and server
:pencil2: create your own CRUD operations with the database you like (Create, Read, Update and Delete)
:no_entry: restrict client access to CRUD operations
:mega: notify in real time clients who are listening for changes in a route, you can choose:
- :no_pedestrians: only specify clients will receive the data
:heavy_check_mark: all clients will receive the data
:lock: accept and deny connection attempts
This is the client side in JavaScript, click here to access the server side in Node.js.
Important links
- Documentation
- chat (example): Chat between the colors blue and green.
- catalog (example): Users adding and removing products from a catalog.
- Getting Started (server)
Getting Started
The "Getting Started" is a example for a Node.js client, but it can be easily changed to SPA's (Vue, Angular, React) by changing how the library is imported (step 3).
1 - First create the server, click here and follow the server instructions in the section "Getting Started"
2 - Install
npm install askless-javascript-client --save
3 - Import the package
JavaScript
// If you will run on the browser
const AsklessClient = require("askless-javascript-client/web").AsklessClient;
// If you will run on Node.js environment
const AsklessClient = require("askless-javascript-client/node").AsklessClient;
TypeScript
import {AsklessClient} from "askless-javascript-client/web";
//or
import {AsklessClient} from "askless-javascript-client/node";
4 - Initialize the server informing the IPV4 address and port (default: 3000).
5 - Perform the connection with AsklessClient.instance.connect()
Example:
AsklessClient.instance.init({
serverUrl: 'ws://192.168.2.6:3000',
});
AsklessClient.instance.connect();
6 - Get real-time data updates
AsklessClient.instance.listen({
route: 'product/tracking',
listen: data => {
console.log("NEW DATA RECEIVED: ");
console.log(data);
},
});
7 - In this example, let's send data to the server every 5 seconds
setInterval(() => {
AsklessClient.instance.create({
route: 'product/customerSaid',
body: 'I\'m waiting'
});
}, 5 * 1000); //every 5 seconds
8 - We need to stop receiving messages from the server in some place of our application, in this example let's stop after 1 minute:
setTimeout(() => {
listening.close();
console.log("Stopped listening");
}, 60 * 1000);
Project ready! You can run :)
Following this links, you can also check this "Getting Started" complete project of the JavaScript client and of the server in Node.js.
Issues
Feel free to open a issue about:
:grey_question: questions
:bulb: suggestions
:page_facing_up: documentation improvements
:ant: potential bugs