简体   繁体   中英

How to extend Composer rest Server

I made a Hyperledger composer Network. I want to see My function that have a query code.

for example, My function' content is

/**
 * @param {hansung.ac.kr.transaction.selectUserByCertificateName}  tx  - the member to be processed
 * @transaction
 */
function selectUserByCertificateName (tx) {
  var idList = [];

  query("selectCertificateByName" , {targetName: tx.certificateName })
  .then(function (certificateList) {
     certificateList.forEach(function (certificate) {
     idList.push(certificate.ownerId);
     })
  }).then(function () {
     idList.forEach(function (id) {
        query("selectUserById" , {targetId: id })
        .then(function (userList){
         console.log(userList); 
        });
     })
  });

}

this case, I attempt to console.log. I want to see this result(userList) in my angular page.

In angular, http.get method is used for receiveing rest-server data
but, I don't know how to editing composer-rest-server response format I want to sending userList to rest Response.

How to extend Composer rest Server ?

if another way To get Data is exist, please give advice

I think it's the wrong approach you're doing. It looks like you want to query something from the custom composer-rest-server having access to your deployed Business Network.

As you want to build a REST query endpoint at the end, you have to implement a simple Hyperledger Composer Query definition . composer-rest-server offers all your query definitions as a GET request.

To learn and understand I can highly recommend you this Composer & REST server query tutorial . Another thing I'd like to recommend you is not to work with console.log at all in transaction processor functions. The logged results can only be seen when executed in a browser connection in Composer Playground or when the code is executed through unit/Cucumber tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM