Hyperledger Composer REST服务报错及概念默认值不显示问题咨询
Hey there! Let's tackle your two connected issues one by one—these are pretty common hurdles when working with asset concepts and the Composer REST server, so let's break down possible causes and fixes:
1. REST Server Error When Starting rest-composer-server
First, let's nail down why the server won't launch. Here are the most likely culprits:
Invalid Asset/Concept Definition Syntax
Even a tiny syntax mistake in yourAirPollutionasset orCarbonMonoxideconcept can crash the server. Run the validation command first to catch issues:composer validateDouble-check your concept's default value definitions—make sure you're using the correct
defaultkeyword (not a typo likedefaults), and that the value matches the property type (e.g., string defaults are wrapped in quotes in YAML/JSON).Dependency Version Mismatch
Outdated or incompatible versions ofcomposer-rest-serveror related packages can cause startup failures. Try updating the server globally:npm install -g composer-rest-serverAlso verify that your
composer-cliversion matches the rest server version withnpm list -g composer-cli composer-rest-server.Database/Connection String Issues
If your server relies on a database (like MongoDB) that's not running, or if your connection string is incorrect, it'll fail to start. Confirm:- The database service is active (e.g.,
sudo systemctl start mongodfor MongoDB) - Your startup command uses the correct business network card, like:
composer-rest-server -c admin@your-air-pollution-network
Ensure the admin identity exists and the network name matches exactly what you deployed.
- The database service is active (e.g.,
2. Missing Concept Default Values in Your Angular App
If the server starts (or you've worked around the first issue) but your Angular app doesn't show pollutant_description/units defaults, here's what to check:
REST Server Isn't Exposing Default Values
By default, the composer REST server might not return default values unless explicitly configured. When starting the server, add the--exposeflag to ensure all properties are included in responses:composer-rest-server -c admin@your-air-pollution-network --exposeTest this first with a tool like Postman: send a POST request to create an
AirPollutionasset without providing theCarbonMonoxidefields, then check if the response includes your default values.Angular Data Binding Path Errors
If the API is returning the defaults but your app isn't showing them, double-check your template bindings. For example, if your asset has aCarbonMonoxideproperty, you need to reference it directly in your template:<!-- Correct --> <p>Description: {{ asset.CarbonMonoxide.pollutant_description }}</p> <!-- Incorrect (will be undefined) --> <p>Description: {{ asset.pollutant_description }}</p>Also, in your component code, make sure you're properly accessing the nested
CarbonMonoxideobject after fetching the asset data.Default Values Aren't Properly Defined in the Concept
Double-check your concept definition to ensure defaults are set correctly. A valid YAML example looks like this:concepts: org.example.AirPollution.CarbonMonoxide: properties: pollutant_description: type: String default: "Colorless, odorless toxic gas" units: type: String default: "ppm"Ensure indentation is correct (YAML is strict about this) and that the
defaultkey is directly under the property it applies to.
Quick Next Steps
- Run
composer validateto fix any syntax issues in your asset/concept definitions - Update your composer-rest-server and verify dependencies
- Test the REST API directly with Postman to confirm default values are returned
- Audit your Angular template bindings and component data handling
内容的提问来源于stack exchange,提问作者kerberos17

