Skip to content

Latest commit

 

History

History
73 lines (53 loc) · 2.81 KB

usage.md

File metadata and controls

73 lines (53 loc) · 2.81 KB

Example Usage

You want to develop a Rust application that can consume the entity sets exposed by an SAP V2 OData service.

For the purposes of instruction, let's say you're working with a custom OData service that displays services ordered either by functional location or by date:

Rust Application zcustom-service-orders
OData Service URL https://my-sap-server.my-domain.com/sap/opu/odata/sap
OData Service Name ZCUSTOM_SERVICE_ORDERS_SRV
OData Schema Name ZCUSTOM_SERVICE_ORDERS
Entity Names SERVICE_ORDERS_BY_FLOC
SERVICE_ORDERS_BY_DATE
Entity Type ZServiceOrder

The general approach to consuming such a service is as follows:

  1. Create a new Rust binary application cargo new zcustom-service-orders

  2. cd zcustom-service-orders

  3. Edit Cargo.toml to include at least the following dependencies

    [build-dependencies]
    parse-sap-odata = { version = "1.4", features = ["parser"]}
    
    [dependencies]
    # Dependencies needed by the code generated by parse-sap-odata
    chrono = { version = "0.4", features = ["serde"]}
    quick-xml = { version = "0.36", features = ["serialize"] }
    rust_decimal = { version = "1", features = ["serde-with-str"]}
    serde = { version = "1.0", features = ["derive"] }
    uuid = { version = "1.8", features = ["serde"]}
    
    # Dependencies needed by this app
    parse-sap-odata = "1.4"
    parse-sap-atom-feed = "1.1"
  4. mkdir odata

  5. In your browser, visit your OData service's metadata

    E.G. https://my-sap-server.my-domain.com/sap/opu/odata/sap/ZCUSTOM_SERVICE_ORDERS_SRV/$metadata

  6. Save the metadata as the file zcustom_service_orders.xml in the odata directory

  7. Create a build.rs file in same directory as Cargo.toml and add at least the following:

    use parse_sap_odata::parser::gen_src;
    
    fn main() {
        gen_src("zcustom_service_orders", "ZCUSTOM_SERVICE_ORDERS");
    }
  8. In src/main.rs include at least:

    use parse_sap_atom_feed::{atom::feed::Feed, odata_error::ODataError, xml::sanitise_xml};
    use std::str::{self, FromStr};
    
    parse_sap_odata::include_mod!("zcustom_service_orders");
    
    use zcustom_service_orders::*;
    
    fn main() {
       let raw_xml: String = /* Whatever code is needed to fetch the entity set data as a raw XML string */
    
       // You might need to sanitise the raw XML string before attempting to parse it
       let clean_xml = sanitise_xml(raw_xml);
    
       let srv_orders_by_floc = Feed::<ZServiceOrder>::from_str(&clean_xml);
    }