Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consume oData service from Delphi

How can I consume a oData webservice from Delphi (I'm trying to interact with the new Bing Search Azure API)? There is almost no information to do this in Delphi. There is a post here but it does not help much explaining how to consume such service from a Delphi point of view. Can anyone provide a simple example?

like image 633
Miguel E Avatar asked Jul 30 '12 12:07

Miguel E


1 Answers

Here is a very simple example of consuming an oData service in Delphi XE using the netflix oData service:

program oDataDemo;

{$APPTYPE CONSOLE}

uses
  SysUtils, msxml, Variants, Activex;

var
  httpRequest: IXMLHttpRequest;
  oDataServiceURI: String;
  oDataFilter: String;
  xmlResults: String;
begin
  try
    oDataServiceURI := 'http://odata.netflix.com/v2/Catalog/Titles()';
    oDataFilter := '?$top=10';
    coinitialize(nil);
    httpRequest := CoXMLHTTP.Create;
    httpRequest.open('GET', UTF8Encode(oDataServiceURI + oDataFilter), false, EmptyParam, EmptyParam);
    httpRequest.send(EmptyParam);
    xmlResults := httpRequest.responseText;
    WriteLn(xmlResults);

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
like image 144
Mattl Avatar answered Oct 03 '22 21:10

Mattl