Invoking RESTful Web Services

RESTful SAS BI Web Services are invoked by sending messages of a particular format to a Web service endpoint in the SAS middle tier. You send request messages to different endpoints depending on which response format you prefer. See Accessing RESTful JSON and XML Web Service Endpoints for more information about how to determine where to send your Web service requests.
When you invoke a RESTful SAS BI Web service, the HTTP headers that you send are important. The Content-type HTTP header tells SAS BI Web Services what type of content you are sending when you perform an HTTP POST. If you are invoking a JSON endpoint, then your Content-type must be set as application/x-www-form-urlencoded and your content must be encoded using this format. If you are invoking an XML endpoint, then your Content-type must be set to application/xml and your content must be XML. The HTTP Accept header tells SAS BI Web Services what type of content your client can accept as output. The Accept header must be set to application/json for JSON endpoints and can be set to application/xml for XML endpoints (this header is not required for XML endpoints). When retrieving binary output resources from an XML endpoint, you can follow normal HTTP procedures for other HTTP headers such as Content-length, Host, and HTTP method.
SOAP, RESTful XML, and RESTful JSON Usage
Stored process (no input required) /programs/timeAndDate
Stored process (input required) /programs/addfloats
Generated Web service addfloatsWS contains stored process /programs/addfloats
SOAP Usage
SOAP endpoint
http://host:port/SASBIWS/services/programs/timeAndDate
http://host:port/SASBIWS/services/programs/addfloats
http://host:port/SASBIWS/services/addfloatsWS
WSDL location
http://host:port/SASBIWS/services/programs/timeAndDate?wsdl
http://host:port/SASBIWS/services/programs/addfloats?wsdl or http://host:port/SASBIWS/services/programs/addfloats.wsdl
http://host:port/SASBIWS/services/addfloatsWS?wsdl or http://host:port/SASBIWS/services/addfloatsWS.wsdl
Sample SOAP request
POST http://host:port/SASBIWS/services/
   programs/timeAndDate 
HTTP/1.1
Content-Type: text/xml; charset=UTF-8 
SOAPAction: 
   “http://www.sas.com/xml/namespace/
   biwebservices/timeAndDate”
Host: host:port

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/
   soap/envelope/" 
xmlns:biw="http://www.sas.com/xml/
   namespace/biwebservices">
   <soapenv:Header/>
   <soapenv:Body>
      <biw:timeAndDate>
         <biw:parameters />
      </biw:timeAndDate>
   </soapenv:Body>
</soapenv:Envelope>
POST http://host:port/SASBIWS/services/
   programs/addfloats 
HTTP/1.1 
Content-Type: text/xml; charset=UTF-8 
SOAPAction: 
   “http://www.sas.com/xml/namespace/
   biwebservices/addfloats” 
Host: host:port

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/
   soap/envelope/" 
xmlns:biw="http://www.sas.com/xml/
   namespace/biwebservices">
   <soapenv:Header/>
   <soapenv:Body>
      <biw:addfloats>
         <biw:parameters>
            <biw:num1>2.3</biw:num1>
            <biw:num2>4.2</biw:num2>
         </biw:parameters>
      </biw:addfloats>
   </soapenv:Body>
</soapenv:Envelope>
POST http://host:port/SASBIWS/services/
   addfloatsWS 
HTTP/1.1 
Content-Type: text/xml; charset=UTF-8 
SOAPAction: 
   “http://tempuri.org/addfloatsWS/
   addfloats” 
Host: host:port

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/
   soap/envelope/" 
xmlns:add="http://tempuri.org/
   addfloatsWS">
   <soapenv:Header/>
   <soapenv:Body>
      <add:addfloats>
         <add:parameters>
            <add:num1>2.3</add:num1>
            <add:num2>4.2</add:num2>
         </add:parameters>
      </add:addfloats>
   </soapenv:Body>
</soapenv:Envelope>
Sample SOAP response
HTTP/1.1 200 OK
SOAPAction: ""
Accept: text/xml
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/
   soap/envelope/">
   <soapenv:Body>
      <n:timeAndDateResponse 
xmlns:n="http://www.sas.com/xml/namespace/
   biwebservices">
         <n:timeAndDateResult>
            <n:Parameters>
               <n:time>13:24:20</n:time>
               <n:date>06Mar2011</n:date>
            </n:Parameters>
         </n:timeAndDateResult>
      </n:timeAndDateResponse>
   </soapenv:Body>
</soapenv:Envelope>
HTTP/1.1 200 OK
SOAPAction: ""
Accept: text/xml
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/
   soap/envelope/">
   <soapenv:Body>
      <n:addfloatsResponse 
xmlns:n="http://www.sas.com/xml/namespace/
   biwebservices">
         <n:addfloatsResult>
            <n:Parameters>
               <n:Sum>6.5</n:Sum>
            </n:Parameters>
         </n:addfloatsResult>
      </n:addfloatsResponse>
   </soapenv:Body>
</soapenv:Envelope>
HTTP/1.1 200 OK
SOAPAction: ""
Accept: text/xml
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/
   soap/envelope/">
   <soapenv:Body>
      <n:addfloatsResponse 
xmlns:n="http://tempuri.org/addfloatsWS">
         <n:addfloatsResult>
            <n:Parameters>
               <n:Sum>6.5</n:Sum>
            </n:Parameters>
         </n:addfloatsResult>
      </n:addfloatsResponse>
   </soapenv:Body>
</soapenv:Envelope>
RESTful XML Usage
RESTful XML endpoint
http://host:port/SASBIWS/rest/storedProcesses/programs/timeAndDate
http://host:port/SASBIWS/rest/storedProcesses/programs/addfloats
http://host:port/SASBIWS/rest/addfloatsWS/addfloats
Sample RESTful XML request
GET http://host:port/SASBIWS/rest/
   storedProcesses/programs/timeAndDate 
HTTP/1.1
Accept: application/xml
Host: host:port
POST http://host:port/SASBIWS/rest/
   storedProcesses/programs/addfloats 
HTTP/1.1
Accept: application/xml
Content-Type: application/xml
User-Agent: Jakarta Commons-HttpClient/3.1
Host: host:port

<addfloats>
   <parameters>
      <num1>2.3</num1>
      <num2>4.2</num2>
   </parameters>
</addfloats>
POST http://host:port/SASBIWS/rest/
   addfloatsWS/addfloats HTTP/1.1
Accept: application/xml
Content-Type: application/xml
Host: host:port

<addfloats xmlns="http://tempuri.org/
   addfloatsWS">
   <parameters>
      <num1>2.3</num1>
      <num2>4.2</num2>
   </parameters>
</addfloats>
Sample RESTful XML response
HTTP/1.1 200 OK
Content-Type: text/xml
Transfer-Encoding: chunked

<timeAndDateResponse>
   <timeAndDateResult>
      <Parameters>
         <time>13:24:20</time>
         <date>06Mar2011</date>
      </Parameters>
   </timeAndDateResult>
</timeAndDateResponse>
HTTP/1.1 200 OK
Content-Type: text/xml
Transfer-Encoding: chunked

<addfloatsResponse>
   <addfloatsResult>
      <Parameters>
         <Sum>6.5</Sum>
      </Parameters>
   </addfloatsResult>
</addfloatsResponse>
HTTP/1.1 200 OK
Content-Type: text/xml
Transfer-Encoding: chunked

<n:addfloatsResponse 
xmlns:n="http://tempuri.org/addfloatsWS">
   <n:addfloatsResult>
      <n:Parameters>
         <n:Sum>6.5</n:Sum>
      </n:Parameters>
   </n:addfloatsResult>
</n:addfloatsResponse>
RESTful JSON Usage
RESTful JSON endpoint
http://host:port/SASBIWS/json/storedProcesses/programs/timeAndDate
http://host:port/SASBIWS/json/storedProcesses/programs/addfloats
http://host:port/SASBIWS/json/addfloatsWS/addfloats
Sample RESTful JSON request
GET http://host:port/SASBIWS/json/
   storedProcesses/programs/timeAndDate 
HTTP/1.1
Accept: application/json
Host: host:port
POST http://host:port/SASBIWS/json/
   storedProcesses/programs/addfloats 
HTTP/1.1
Accept: application/json
Content-Type: 
   application/x-www-form-urlencoded
Host: host:port

num1=2.3&num2=4.2
POST http://host:port/SASBIWS/json/
   addfloatsWS/addfloats 
HTTP/1.1
Accept: application/json
Content-Type: 
   application/x-www-form-urlencoded
Host: host:port

num1=2.3&num2=4.2
Sample RESTful JSON response
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked

{"outputParameters":{"date":"06Mar2011",
   "time":"13:24:20"}}
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked

{"outputParameters":{"Sum":"6.5"}}
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked

{"outputParameters":{"Sum":"6.5"}}
RESTful Output Resource Access
Stored process (no input required) /programs/outputTest
Stored process (input required) /programs/ioTest
Generated Web service outputTestWS contains stored process /programs/outputTest
Original RESTful URL
http://host:port/SASBIWS/rest/storedProcesses/programs/outputTest
http://host:port/SASBIWS/rest/storedProcesses/programs/ioTest
http://host:port/SASBIWS/rest/storedProcesses/outputTestWS/outputTest
Accessing an output parameter named result that returns a value success
Endpoint
http://host:port/SASBIWS/rest/storedProcesses/programs/outputTest/parameters/result
http://host:port/SASBIWS/rest/storedProcesses/programs/ioTest/parameters/result
http://host:port/SASBIWS/rest/outputTestWS/outputTest/parameters/result
Sample request
GET http://host:port/SASBIWS/rest/
   storedProcesses/programs/outputTest/
   parameters/result
HTTP/1.1
Host: host:port
POST http://host:port/SASBIWS/rest/
   storedProcesses/programs/outputTest/
   parameters/result
HTTP/1.1
Host: host:port

<outputTest>
   <sampleInput>
      Foo
   </sampleInput>
</outputTest>
GET http://host:port/SASBIWS/rest/
   outputTestWS/outputTest/parameters/
   result
HTTP/1.1
Host: host:port
Sample response
HTTP/1.1 200 OK
Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 7

success
Accessing a data target named strOut that returns XML
Endpoint
http://host:port/SASBIWS/rest/storedProcesses/programs/outputTest/streams/strOut
http://host:port/SASBIWS/rest/storedProcesses/programs/ioTest/streams/strOut
http://host:port/SASBIWS/rest/outputTestWS/outputTest/streams/strOut
Sample response
HTTP/1.1 200 OK
Content-Type: text/xml;charset=utf-8

<streamOutput>contents</streamOutput>
Accessing a data target named pdfOut that returns a PDF (binary data)
Endpoint
http://host:port/SASBIWS/rest/storedProcesses/programs/outputTest/streams/pdfOut
http://host:port/SASBIWS/rest/storedProcesses/programs/ioTest/streams/pdfOut
http://host:port/SASBIWS/rest/outputTestWS/outputTest/streams/pdfOut
Sample response
HTTP/1.1 200 OK
Content-Type: application/pdf

%PDF-1.3
%Äåòåë§ó ÐÄÆ
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x­›ÝŽ7…ïû)x…
Accessing the third entry in package output which is a PDF file
Endpoint
http://host:port/SASBIWS/rest/storedProcesses/programs/outputTest/packages/2
http://host:port/SASBIWS/rest/storedProcesses/programs/ioTest/packages/2
http://host:port/SASBIWS/rest/outputTestWS/outputTest/packages/2
Sample response
HTTP/1.1 200 OK
Content-Type: application/pdf

%PDF-1.3
%Äåòåë§ó ÐÄÆ
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x­›ÝŽ7…ïû)x…