I am writing web API to get users data from multi-index table data. Below is my API method:
[HttpGet]
public async IAsyncEnumerable<GetTableRowsResponse> GetUsers()
//public async Task<IHttpActionResult> GetUsers()
{
Eos eos = new Eos(new EosConfigurator()
{
HttpEndpoint = "http://127.0.0.1:8888/v1/chain", //running nodeos on localhost
ChainId = "nodeoschainid",
ExpireSeconds = 60,
SignProvider = new DefaultSignProvider("MyPK")
});
var result = await eos.GetTableRows(new GetTableRowsRequest()
{
json = true,
code = "groupacc",
scope = "groupacc",
table = "users"
});
yield return result;
}
This is throwing exception:
ApiErrorException: Exception of type 'EosSharp.Core.Exceptions.ApiErrorException' was thrown.
I have users data in multi-index table users and return all users from API. can anybody help me with the error and return types? Also I am not sure about return type IAsyncEnumerable and yield return with async.
I used JsonConvert
. The complete code is below:
public async Task<string> GetUsers(string code, string scope, string table)
{
try
{
Eos eos = new Eos(new EosConfigurator()
{
HttpEndpoint = "http://127.0.0.1:8888/v1/chain",
ChainId = "nodeoschainid",
ExpireSeconds = 60,
SignProvider = new DefaultSignProvider("MyPK")
});
GetTableRowsResponse result = await eos.GetTableRows(new GetTableRowsRequest()
{
json = true,
code = "groupacc",
scope = "groupacc",
table = "users"
});
string resultJson = JsonConvert.SerializeObject(result.rows);
return resultJson;
}
catch (Exception)
{
throw;
}
}