Published on :
Utility EXTERNE

HTTP GET Request with Basic Authentication and JSON Processing

This code is also available in: Deutsch Español Français
Awaiting validation
The script uses the `PROC HTTP` procedure to initiate a GET request to the endpoint `http://httpbin.org/basic-auth/chris/pass125`. It configures basic authentication with username 'chris' and password 'pass125'. The API response is saved to a temporary file ('fileref resp'). Subsequently, a `DATA _NULL_` step uses the `JSONPP` function to parse and format the JSON content of the response, displaying the result in the SAS© log. This allows interaction with external web services and visualization of their structured responses.
Data Analysis

Type : EXTERNE


The data processed by the script comes from an external source, specifically the URL `http://httpbin.org/basic-auth/chris/pass125`, via an HTTP GET request.

1 Code Block
PROC HTTP Data
Explanation :
This block initializes a temporary fileref named 'resp' to store the output of the HTTP request. The `PROC HTTP` procedure is then used to send a GET request to the specified URL, including basic authentication with the provided credentials. The JSON response from the server is saved to the file associated with the 'resp' fileref.
Copied!
1filename resp temp;
2PROC HTTP
3 url="http://httpbin.org/basic-auth/chris/pass125"
4 method="GET"
5 AUTH_BASIC
6 out=resp
7 webusername="chris"
8 webpassword="pass125"
9 ;
10RUN;
2 Code Block
DATA STEP
Explanation :
This `DATA _NULL_` step does not create a permanent SAS dataset. It uses the `JSONPP` function to read the JSON content from the 'resp' file (the `PROC HTTP` response) and format it for readability, displaying the result directly in the SAS log. This allows for easy inspection of the JSON response's structure and content.
Copied!
1DATA _null_;
2 rc = jsonpp('resp','log');
3RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.