fabric-samples/asset-transfer-basic/rest-api-go
Mark S. Lewis bdaeac199d
Update Go error handling for v1.10 client API (#1362)
The Fabric Gateway client API v1.10.0 provides simplified access to Go
error details. This change updates sample client application to use this
latest version of the client API, and updates Go client applications to
reflect the error handling changes.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2025-11-10 09:53:58 +09:00
..
web Explicitly specify hash in client applications 2024-10-07 12:25:40 -04:00
.gitignore REST api added for asset transfer in Golang (#836) 2022-12-14 09:16:09 +01:00
go.mod Update Go error handling for v1.10 client API (#1362) 2025-11-10 09:53:58 +09:00
go.sum Update Go error handling for v1.10 client API (#1362) 2025-11-10 09:53:58 +09:00
main.go Update Go gRPC dependency 2024-04-24 16:24:37 +09:00
README.md REST api added for asset transfer in Golang (#836) 2022-12-14 09:16:09 +01:00

Asset Transfer REST API Sample

This is a simple REST server written in golang with endpoints for chaincode invoke and query.

Usage

  • Setup fabric test network and deploy the asset transfer chaincode by following this instructions.

  • cd into rest-api-go directory

  • Download required dependencies using go mod download

  • Run go run main.go to run the REST server

Sending Requests

Invoke endpoint accepts POST requests with chaincode function and arguments. Query endpoint accepts get requests with chaincode function and arguments.

Sample chaincode invoke for the "createAsset" function. Response will contain transaction ID for a successful invoke.

curl --request POST \
  --url http://localhost:3000/invoke \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data = \
  --data channelid=mychannel \
  --data chaincodeid=basic \
  --data function=createAsset \
  --data args=Asset123 \
  --data args=yellow \
  --data args=54 \
  --data args=Tom \
  --data args=13005

Sample chaincode query for getting asset details.

curl --request GET \
  --url 'http://localhost:3000/query?channelid=mychannel&chaincodeid=basic&function=ReadAsset&args=Asset123'