How to consume an OData Service?
OData Service consumption is standardized.
OData for Analytics allows to execute and retrieve the result of Business Analytics Reports.
Modeled OData services are based on Business Objects (BO) and support Create, Retrieve, Update, and Delete (CRUD) operations as well as Function Imports to access BO queries and BO actions.
It depends on the used programming language, environment and framework, how the modeled OData service can be accessed, that is: how an HTTP request can be triggered.
Usage is similar/equal in all cases: An HTTP request to the URL (Collection, Entity, or Function Import) with the according HTTP method is created, and (field, value) data and/or options are passed as required.
The service responds with a status code and according data, if available.
In case of success, a success status code 2xx is returned.
In case of error, an error status code 4xx/5xx is returned depending on the type or error.
Direct support is best only for GET and POST. All other methods PUT/PATCH/MERGE/DELETE may or may not be supported. Servers, proxies, and clients often do not support them directly. Sometimes they are rejected by a firewall.
For best compatibility, send a POST request and set header x-http-method to the according method.
If it is PATCH or MERGE depends on the available support.
Besides x-http-method the header x-http-method-override could be evaluated.
For SAP Business ByDesign uses request method POST and header x-http-method MERGE.
Instances are created with a POST request. The created instance is returned.
The OData Framework supports the creation of hierarchies. For example the supplied data could specify a ROOT node with one or even multiple ITEM nodes and/or other child nodes.
The framework responds with the topmost created node. The hierarchy needs to be read if required.
Data Created node. If a hierarchy was created, the topmost created node.
Data is retrieved with a GET request. The URL describes what is exactly retrieved. Therefore the result could be 0, 1 or many entries.
Data is updated with a PUT, or PATCH or MERGE request. The difference is the scope of the modification.
PUT replaces the data. Provided fields are modified, unstated are reset to their defaults.
PATCH (or MERGE) modifies only the provided fields.
A BO modify is done. Hence other fields or nodes could have been changed as a consequence.
An instance is removed with a DELETE request, based on the ObjectID.