Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/micro/micro-js
Micro JS Client
https://github.com/micro/micro-js
js micro
Last synced: about 2 months ago
JSON representation
Micro JS Client
- Host: GitHub
- URL: https://github.com/micro/micro-js
- Owner: micro
- License: apache-2.0
- Created: 2021-11-17T22:03:47.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-20T14:08:42.000Z (about 3 years ago)
- Last Synced: 2024-10-11T22:36:31.529Z (3 months ago)
- Topics: js, micro
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/micro-js-client
- Size: 125 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Micro JS Client
The JS client for the Micro Platform.
View on [NPM](https://www.npmjs.com/package/micro-js-client)
## Usage
Installation:
```
npm install --save micro-js-client
```## Request
Make a standard http request
```js
const micro = require('micro-js-client');new micro.Client({ token: 'MICRO_API_TOKEN' })
.call('helloworld', 'call', {"name": "Alice"})
.then((response) => {
console.log(response);
});
```The output will be:
```
{ message: 'Hello Alice' }
```## Streaming
Make a websocket streaming request
```js
const micro = require("micro-js-client")new micro.Client({ token: 'MICRO_API_TOKEN' })
.stream("helloworld", "stream", {"name": "Alice", "messages": 10})
.then(stream => {
stream.recv(msg => {
console.log("message received: ", msg)
})
}).catch(e => {
console.log(e)
})setInterval(() => {}, 5000);
```
Above example will output:
```
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
message received: { message: 'Hello Alice' }
```## Format
The JS client uses the Micro API to make requests. Just pass `service`, `endpoint` and the json `request`.
The call `/helloworld/call` routes to the service `helloworld` and endpoint `Call`. So just do:
```js
micro.Client.call("helloworld", "call", {"name": "Alice"})
```