Skip to content

microservice-framework/microservice-client

Repository files navigation

microservice-client

Gitter npm microservice-frame.work

Microservice framework client.

On webBrowser level is possible to use AJAX and WebSocket. See examples here.

    <script src="http://microservice-frame.work/js/microservice-client.min.js"></script>
    <script>
$(function() {    
    var clientSettings = {
      URL: "wss://apiserver.com/ws_endpoint/",
      token: 'secureKey or AccessToken'
    }
    ws = new MicroserviceWebSocket(clientSettings);
    ws.on('message', function(object){
      console.log(object);
    });
});
    </script>
    <script src="http://microservice-frame.work/js/microservice-client.min.js"></script>
    <script>
$(function() {    
    var clientSettings = {
      URL: "https://apiserver.com/service",
      secureKey: 'ServiceSecureKey'
    }
    client = new MicroserviceClient(clientSettings);
    client.search({}, function(err, handlerResponse){
      if(err){
        return $('#result').html(err);
      }
      $('#result').html(JSON.stringify(handlerResponse, null, 2));
    });
});

$(function() {    
    var clientSettings = {
      URL: "https://apiserver.com",
      secureKey: 'ServiceSecureKey'
    }
    client = new MicroserviceClient(clientSettings);
    client.search('endpoint', {}, function(err, handlerResponse){
      if(err){
        return $('#result').html(err);
      }
      $('#result').html(JSON.stringify(handlerResponse, null, 2));
    });
});
    </script>

Nodejs:

'use strict';

const MicroserviceClient = require('@microservice-framework/microservice-client');

require('dotenv').config();

var client = new MicroserviceClient({
  URL: "http://localhost:" + process.env.PORT,
  secureKey: process.env.SECURE_KEY
});

var RecordID;
var RecordToken;

client.post({
    name: "Microservice",
    data: {
      value: test
    }
  }, function(err, handlerResponse){
    console.log(handlerResponse);
    RecordID = handlerResponse.id;
    RecordToken = handlerResponse.token;
    
    client.search({
      name: "Microservice"
      }, function(err, handlerResponse){
        console.log(handlerResponse);
    });
    
    client.get(RecordID, RecordToken, function(err, handlerResponse){
      console.log(handlerResponse);
    });
    
    client.put(RecordID, RecordToken, {
      extra: {
        extravalue: "test2"
      }
    }, function(err, handlerResponse){
      console.log(handlerResponse);
    });
    
    client.delete(RecordID, RecordToken, function(err, handlerResponse){
      console.log(handlerResponse);
    });
});

Changelog

  • 1.2.5
    • added nodejs package name to UserAgent
    • fixed URL variable
    • added support for API based requests
  • 1.3.0
    • switch to 'Access-Token' instead of 'access_token'
    • support new validation for microservices
  • 1.3.1
    • prevent autoset User-Agent if package linked by browser
  • 1.3.2
    • replace const with var for uglify compatibility.
  • 1.3.3
    • allow to replace header 'Accept'
  • 1.3.4
    • fix error when parse empty response as JSON.