How do you use the new HttpApi with DataAbstract? Are the Rest routes automatically created for adding a new record, editing a record, deleting a record for a table, etc?
Thanks.
How do you use the new HttpApi with DataAbstract? Are the Rest routes automatically created for adding a new record, editing a record, deleting a record for a table, etc?
Thanks.
why would you want to? what’s the goal?
We have a separate REST and OData v1 dispatchers for Data Abstract that allow to manupulate data using Http queries. However the paths that REST dispatcher provides are not displayed in the OpenAPI service description. I can create a simple sample if you want to know more about this feature.
Anton, thank you for your reply. I would very much appreciate a simple sample that shows how DataAbstract can be used for Rest operations on database tables.
Our goal is to provide a REST api interface to our database tables for adding new records, editing records, deleting records, and querying the tables from our Non-RemObjects client applications.
Thank you.
Bill Brittain
Hello
The sample server is attached: REST_SampleServer.zip (50.0 KB)
It uses the standart sample SQLite database shipped with Data Abstract.
Accessing a table:
GET http://localhost:8099/rest/Customers
Accessing a table with some condition applied:
GET http://localhost:8099/rest/Customers?filter=Name%20LIKE%20%27%An%%27
Accessing single record in the table:
GET http://localhost:8099/rest/Customers/{3217032b-47db-400a-9a6e-012cbdf1e1e5}
Inserting a row
POST http://localhost:8099/rest/Customers
with a body like
{"Id":"{11111111-1111-1111-1111-111111111111}","Name":"Ana Trujillo","Phone":"(5) 555-4729","Address":"c6be7eec-6a39-48c1-b2c5-5b2c1edbff51","Remarks":"Set on server at 26.10.2017 14:03:37","Discount":0}
As you can see the body represents full object to be inserted.
Note: There is no way to report back new ID if AutoInc fields are used. Actually there is no way to send back any server-calculated field values.
Note: There is no way to perform several data update operations in one transaction.
Updating a row
PUT http://localhost:8099/rest/Customers/{11111111-1111-1111-1111-111111111111}
with a body like
{"Id":"{11111111-1111-1111-1111-111111111111}","Name":"Updated Value","Phone":"(5) 555-4729","Address":"c6be7eec-6a39-48c1-b2c5-5b2c1edbff51","Remarks":"Set on server at 26.10.2017 14:03:37","Discount":0}
Deleting a row:
DELETE http://localhost:8099/rest/Customers/{11111111-1111-1111-1111-111111111111}
As you can see the REST dispatcher provides a simple way to access the data, however it is limited in some areas. For more advanced scerarios like inserting a master-detail object in one batch you’ll need to write separate service methods.
Regards
Thank you Anton. I very much appreciate the example code.
Bill Brittain
HI, Can I have Delphi Version Sample?
Joe
Hello
The sample server is attached: ODataServer (Delphi).zip (63.3 KB)
It uses the standard sample SQLite database shipped with Data Abstract.
Accessing a table:
GET http://localhost:8099/odata/Customers?$format=json
Accessing a table with some condition applied:
GET http://localhost:8099/odata/Customers?$format=json&$filter=Name eq 'Ana Trujillo'
Accessing single record in the table:
GET http://localhost:8099/odata/Customers/{3217032b-47db-400a-9a6e-012cbdf1e1e5}?$format=json
Inserting a row
POST http://localhost:8099/odata/Customers?$format=json
with a body like
{"d":{
"__metadata": {
"uri": "http://localhost:8099/odata/Customers",
"type": "ODataService.Customers"
},
"Id":"{11111111-1111-1111-1111-111111111111}","Name":"Ana Trujillo","Phone":"(5) 555-4729","Address":"c6be7eec-6a39-48c1-b2c5-5b2c1edbff51","Remarks":"Set on server at 26.10.2017 14:03:37","Discount":"0"}}
As you can see the body represents full object to be inserted.
Note: There is no way to report back new ID if AutoInc fields are used. Actually there is no way to send back any server-calculated field values.
Note: There is no way to perform several data update operations in one transaction.
Updating a row
PUT http://localhost:8099/odata/Customers('{11111111-1111-1111-1111-111111111111}')?$format=json
with a body like
{"d":{
"__metadata": {
"uri": "http://localhost:8099/odata/Customers",
"type": "ODataService.Customers"
},
"Id":"{11111111-1111-1111-1111-111111111111}","Name":"Updated Value","Phone":"(5) 555-4729","Address":"c6be7eec-6a39-48c1-b2c5-5b2c1edbff51","Remarks":"Set on server at 26.10.2017 14:03:37","Discount":0}
}
Deleting a row:
DELETE http://localhost:8099/odata/Customers('{11111111-1111-1111-1111-111111111111}')?$format=json
As you can see the ODATA dispatcher provides a simple way to access the data, however it is limited in some areas. For more advanced scenarios like inserting a master-detail object in one batch you’ll need to write separate service methods.
Sorry to resurrect but, as the HttpApi stuff is now available on Delphi, is there a Delphi version of the REST server available anywhere?
Hello
What exactly do you mean - a REST server built using HttpAPI or a REST server that accessed data (like the .NET sample).
Please note that unfortunately the latter one is not supported right now.
Regards
Ah yes it was the latter, accessing data via REST.
We have a similar requirement to the OP - a fully functional server and client, both in Delphi, but have been tasked with investigating providing a REST API on the server alongside the native RemObjects one, to permit data access from arbitrary clients.