HttpAPI + DA

Hi,

I just checked the httpAPI information. I want to confirm any example for delphi DA server through httpApi for table searching , insert, edit through json?

Like I query a table with criteria return a json data, or I pass a editing json data(similar to your ,net example).

Any exmaple or advise ? if not yet support, any dataset to json , json to dataset tools or helps utilies?

for the JWT, from the discussion, seems no natively solution. Any advise on delphi to implement it ? Any example?

Joe

Hi,

you can use Odata in json mode. though we support only Odata v1, it is possible to perform common operations like Select, Insert, Update, Delete.
correspondent http methods will be:

  • GET /path/%table - to a listing of ALL records in table
  • GET /path/%table/%IDVALUE - to a listing of just that record
  • POST - add a new record
  • PUT /path/%table/%IDVALUE - to update a record in the table
  • DELETE /path/%table/%IDVALUE - to delete a row.

see examples in What's happening with ODATA? topic


you can convert any dataset to IDADataset with uDADatasetWrapper.TDatasetWrapper.
later this IDADataset can be serialized/deserialized to/from json with uDAJSONDataStreamer.TDAJSONDataStreamer.

My case is I try to use HttpAPI way As the client is vue.js :

Get Json Data by post/get like below:

function TDataService.GetIOP(const SWHERE: UnicodeString): UnicodeString;
var
  srcData: IDADataset;
  sjson:TDAJSONDataStreamer;
begin
  srcData := Schema.NewDataset(connection,'IOP_NAME_LIST',['IOP_NAME_SIM_LNG'],[SWHERE]) ;
  sjson:=TDAJSONDataStreamer.Create(Self);


sjson.Initialize(stream,aiwrite);
try
  sjoson.WriteDataset(srcData, [woSchema, woRows], -1);
finally
  sjoson.Finalize;
end;

end;

As before I use this for binary stream but now is json. how to change it?

or I should declare the return value as binary also for the json. please advise.

I want to post back the changed json, decode and post to db.
Any hints to manually decode it?

joe

Hi,

pls read the HttpAPI in details article.

I’ve following the article and make the changes but hit error:

2020-08-15_00h28_45

Below is the code, please advise.

[ROServiceMethod]
[ROCustom('HttpApiPath','iop')]
 function GetIOP([ROCustom('httpapiheaderparameter', '1')] const SWHERE: UnicodeString): TROHttpApiResult; virtual;



function TDataService.GetIOP(const SWHERE: UnicodeString): TROHttpApiResult;
var
  srcData: IDADataset;
  sjoson:TDAJSONDataStreamer;
begin
  Result := TROHttpApiResult.Create(HTTP_200_code, id_ContentType_application_json_charset_utf8,'',false);

  srcData := Schema.NewDataset(connection,'IOP_NAME_LIST',['IOP_NAME_SIM_LNG'],[SWHERE]) ;
  sjoson:=TDAJSONDataStreamer.Create(Self);


sjoson.Initialize(Result,aiwrite);
try
  sjoson.WriteDataset(srcData, [woSchema, woRows], -1);
finally
  sjoson.Finalize;
end;

end;.

I change the [ROServiceMethod] to [ServiceMethod]. It can run,

But http://localhost:8099/api/, I cannot check the method.

{"swagger":"2.0","info":{"title":"RestAPi_Prj","version":"1.0.0"},"basePath":"\/api","consumes":["application\/json"],"produces":["application\/json"],"paths":{},"securityDefinitions":{"Bearer":{"type":"apiKey","name":"Access-Token","in":"header"}}}

Do I miss any ?

pleasae advise

Hi,

just change your declaration to Binary:

[ROServiceMethod]
[ROCustom('HttpApiPath','iop')]
 function GetIOP([ROCustom('httpapiheaderparameter', '1')] const SWHERE: UnicodeString): Binary; virtual;

w/o changing method body. after this, it should work as expected.