- Simone Olianti
- SnapObjects
- Friday, 20 September 2019 04:01 PM UTC
Hello, i am quite new to web apis but following the "CRUD Operations with .NET DataStore" i was able to publish my first web api, created my own data context and successfully generated my first c# datastore model. Also created the controller to retrieve data and successfully accessed it from a pb application using RESTClient.
How cool is that? :)
Now my question is:
Having a datastore with a retrieval argument (i.e. date type) how do i call the method to retrieve data passing a parameter? What should i put in the URL?
this is what i did in the services interface
using PowerBuilder.Data;
namespace StartWebApi1.Services
{
public interface IDayFatService
{
IDataStore RetrieveByDate(string dataoggi);
}
}
and the service like this:
public IDataStore RetrieveByDate(string dataoggi)
{
var dss_DayFat = new DataStore("dss_dayfat", _context);
dss_DayFat.Retrieve(dataoggi);
return dss_DayFat;
}
in the controller:
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult RetrieveByDate(string dataoggi)
{
IDataStore dss_DayFat = new DataStore("dss_dayfat");
try
{
dss_DayFat = _dayfatservice.RetrieveByDate(dataoggi);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
if (dss_DayFat.RowCount
{
return NotFound("No rows retrieved.");
}
else
{
return Ok(dss_DayFat);
}
}
first of all i am not sure if i have to use a "string" type to define the parameter, but how do i build the url to call the api from pb?
inv_RestClient.sendgetrequest("http://xxx.xxx.xxx.xxx:82/api/dayfat/retrievebydate???????", ls_response)
any help would be appreciated
TIA,
simone
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.