questions regarding metadata

Feb 11, 2011 at 8:57 AM


I have a question about metadata. How can I access the metadata document through the datajs API?

Do I have to access the document on my own and hand the parts which are relevant for data retrieval to the method?

Is it then necessary to create a custom handler too?

Or how works the data retrieval with regards to metadata?

Is there an example how to use metadata with datajs and in which format it should be provided for the method?

Another question: Does datajs read the metadata document and validate it itself before sending a request?

Thank you!

Feb 11, 2011 at 6:07 PM

Hi ironmanager, can be used to read and parse the metadata document from the service. Out of the box datajs comes with a handler, so it is not necessary for you to create a custom one; however it does not automatically choose it when parsing, so you do need to specify it as the last argument to, as follows:"<serviceRoot>/$metadata", function (metadata) {
    // success callback
}, function (error) {
    // error callback
}, OData.metadataHandler);

On a successful response, the success callback will be called with the deserialized representation of the metadata passed in (the "metadata" variable in the example above). You can then pass this object into a subsequent call to instruct that call to use the metadata, as follows:"<serviceRoot>/<endpoint>", function (data) {
    // success callback
}, function (error) {
    // error callback
}, undefined, undefined, metadata);

Alternatively, if you are working with a single service and you'll be making multiple data reads that need to make use of the metadata, you can push the metadata onto the metadata stack:


and then call on your data endpoints without needing to pass the metadata object into every call.

datajs does not perform any validation on the metadata document -- it assumes the server sends the correct document.

Hope that answers all your questions! Please let me know if you have any more issues.