https://github.com/connect-platform/ng-connect
Connect to CONNECT platform instances easily in Angular 2+
https://github.com/connect-platform/ng-connect
Last synced: 5 months ago
JSON representation
Connect to CONNECT platform instances easily in Angular 2+
- Host: GitHub
- URL: https://github.com/connect-platform/ng-connect
- Owner: CONNECT-platform
- Created: 2018-10-19T17:44:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-21T21:08:41.000Z (over 7 years ago)
- Last Synced: 2024-12-30T22:43:35.327Z (about 1 year ago)
- Language: TypeScript
- Size: 115 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NgConnect
Easy interface with CONNECT platform instances.
_I mean, its generally not tough to interface with backend services in angular, and CONNECT platform instances are also pretty straight-forward. However, I am personally the lazy type, and since the signature of CONNECT instances is known before hand and is pretty easy to handle, this would make it easier on the client side to speak with them. Note that of course this package can work with any **InterConnectible** service._
## How To Install
```bash
npm install ng-connect
```
## How To Import
Import the module `NgConnectModule` and the service `NgConnectService` in your main module file (`app.module.ts`),
add `NgConnectModule` to `@NgModule`'s `imports` field and `NgConnectService` to its `providers` field:
```typescript
import { NgConnectModule, NgConnectService } from 'ng-connect';
@NgModule({
/* ... */
imports: [
/* ... */
NgConnectModule,
],
providers: [
/* ... */
NgConnectService,
],
/* ... */
})
export class AppModule { /* ... */ }
```
## How To Use
You need to create one backend instance per backend service you want to connect to. I would personally suggest creating a service that manages these backend instances, however you can create them wherever you have access to DI.
```typescript
import { NgConnectService, ConnectBackend } from 'ng-connect';
class SomeDIInitiatedClass {
private backend: ConnectBackend;
constructor(connect: NgConnectService) {
this.backend = connect.createBackend('https://my-connect-backend.connect-platform.com');
//
// the backend does not connect itself, to give you control over when to connect it.
//
this.backend.connect().subscribe(() => console.log('CONNECTED!'));
}
}
```
Then you can make calls to backend nodes easily:
```typescript
let response = this.backend.call('/some/node/', {
a: 'some value',
b: 'some other value',
});
response.out.X.subscribe(outX => console.log('X:: ' + outX));
response.out.Y.subscribe(outY => console.log('Y:: ' + outY));
response.control.Z.subscribe(() => console.log('Z!'));
```
this is assuming that `/some/node/` has the following signature:
```json
{
"path" : "/some/node",
"inputs" : ["a", "b"],
"outputs" : ["X", "Y"],
"controlOutputs" : ["Z"]
}
```
the backend will receive the whole registry signature upon connection (invokation of `connect()`), and hence will automatically figure out the proper method of the request, the proper way to send the data, etc. if insufficient inputs are provided, the backend will check on the client side and throw proper errors.
**NOTE** the request will be made upon invokation of `backend.call()` and does not matter if you subscribe to the response object or not. If you subscribe after the server has responded, obviously you will miss out on the data.