Using the REST Library: Difference between revisions

m
Corrections
m (Cat)
m (Corrections)
Line 11: Line 11:
Then again do: File --> New --> Other --> DataFlex Source File, this time naming it '''ApiCustomersHandler'''. Into that blank file drag an object of the cRestResourceHandler class. Change the object's name to oApiCustomersHandler and set its psInterfacePath property (an empty string by default) to "'''customers'''".
Then again do: File --> New --> Other --> DataFlex Source File, this time naming it '''ApiCustomersHandler'''. Into that blank file drag an object of the cRestResourceHandler class. Change the object's name to oApiCustomersHandler and set its psInterfacePath property (an empty string by default) to "'''customers'''".


Then in the DDO Explorer pane (lower-right in the Studio by default) click the "+" book icon (Add DDO) and select the cCustomerDataDictionary.
Then in the DDO Explorer pane (lower-right in the Studio by default) click the "<font color="green">+</font>" book icon (Add DDO: [[File:Add DD.jpg|15px]]) and select the cCustomerDataDictionary.


Drag a cRESTApiObject from the class palette to below the comment "''Add your cRESTApiObjects here''". Rename it to "oCustomers". Set its phoDD property to oCustomer_DD, its psCollName (collection name) property to "'''customers'''" (plural) and its psInstName (instance name) property to "'''customer'''" (singular).
Drag a cRESTApiObject from the class palette to below the comment "''Add your cRESTApiObjects here''". Rename it to "oCustomers". Set its phoDD property to oCustomer_DD, its psCollName (collection name) property to "'''customers'''" (plural) and its psInstName (instance name) property to "'''customer'''" (singular).
Line 114: Line 114:
</source>
</source>


Now you can immediately see the saving: 81 lines (most of which were written for you and a couple of which are comments I have added for clarification) vs. the 574 lines in the [[A Simple RESTful Service|Simple]] example, while most of the functionality is essentially the same (a careful examination with reveal a bit more "[https://en.wikipedia.org/wiki/HATEOAS ''HATEOAS'']"-type information in some of the returned JSON in the former).
Now you can immediately see the saving: 81 lines (most of which were written for you and a couple of which are comments I have added for clarification) vs. the 574 lines in the [[A Simple RESTful Service|Simple]] example, while most of the functionality is essentially the same (a careful examination will reveal a bit more "[https://en.wikipedia.org/wiki/HATEOAS ''HATEOAS'']"-type information in some of the returned JSON in the former).


In addition this approach has much more generality and extensibility: additional cRESTApiObjects (and DDOs) can be added to the cApiCustomersHandler to provide for dependant sub-collections (since customers have orders, and orders have details), while other cRESTResourceHandler objects can be added to handle other top-level collections (orders, vendors, inventory, salespeople and so on).
In addition, this approach has much more generality and extensibility: additional cRESTApiObjects, and the corresponding DDOs, can be added to the cApiCustomersHandler to provide for dependant sub-collections (since customers have orders, and orders have details), while other cRESTResourceHandler objects can be added to handle other top-level collections (orders, vendors, inventory, salespeople and so on).


The library (in the cRESTApiObjects) provides mechanisms to exclude specific fields from the interface (Send AddExcludeColumn ''Table.Column''), or mark them as read-only through it (Send AddReadOnlyColumn ''Table.Column''), include parent columns in collections or instances (through the AddListColumn and AddInstanceColumn procedures) and even provide calculated pseudo-columns (AddListFunctionColumn and AddInstanceFunctionColumn). Entire collections can be set as read-only (pbReadOnly), no-update (pbNoUpdate) or no-delete (pbNoDelete).
The library (in the cRESTApiObjects) provides mechanisms to exclude specific fields from the interface (Send AddExcludeColumn ''Table.Column''), or mark them as read-only through it (Send AddReadOnlyColumn ''Table.Column''), include parent columns in collections or instances (through the AddListColumn and AddInstanceColumn procedures) and even provide calculated pseudo-columns (AddListFunctionColumn and AddInstanceFunctionColumn). Entire collections can be set as read-only (pbReadOnly), no-update (pbNoUpdate) or no-delete (pbNoDelete).