tags:

views:

259

answers:

3

This is sort of an odd question. I know that SAS has a PROC SOAP for consuming web services. I wonder if anyone has any experience consuming XML from a REST resource using SAS?

+2  A: 

I haven't had specific experience with REST APIs from SAS, but I've worked with similar web-based services.

You can use the filename url engine to access arbitrary URLs and read the results back. YMMV as far as compatibility with particular REST APIs and XML output goes.

Alternatively, you could use system calls to programs like wget or curl to download the XML into a file, then parse the input using SAS' xml engine.

Rog
Thanks Rog, In most cases I only want to retrieve a string so maybe filename url will be enough for me.
Jeffrey Cameron
+2  A: 

In Base SAS 9.2 there is also a new proc called proc http. It was designed specifically to call REST services (or for site scraping). You could also use the url access method for simple get requests. The advantage of proc http is that you can control the http verb used and also pass a payload.

Zach
awesome! Thank you. Looks a bit easier to use than filename url as well!
Jeffrey Cameron
A: 

i found this post hope be useful for u

http://blog.flair-systems.com/2010/05/how-to-consume-rest-based-services.html

Q. How to consume REST based-services?

Assume we have REST based-service contains method Add which takes two operands op1 and op2 and return the summation.

A) Create any project type (Console, Windows or even Web-based application) and add the below lines :

Code Snippet

  1. using System.Net;
  2. using System.IO;

B) Write some code to consume the service:

Code Snippet

  1. string parameters;
  2. string response;
  3. // Create the request obj
  4. WebRequest request = WebRequest.Create("serviceURL/Add");
  5. // Set values for the request back
  6. request.Method = "POST"; //REST based-services using Post method
  7. request.ContentType = "application/json"; //tells request the content typs is JSON
  8. parameters = "{\"op1\":2,\"op2\":\"1\"}";
  9. request.ContentLength = parameters.Length;
    1. // Write the request
    2. StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
    3. requestWriter.Write(parameters);
    4. requestWriter.Close();
    5. // Do the request to get the response
    6. StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream());
    7. response = responseReader.ReadToEnd();
    8. responseReader.Close();

Response value should be 3 if you implement Add method correctly :))

Waleed Mohamed