Skip to main content
U.S. flag

An official website of the United States government

Here’s how you know

Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

VSAC SVS Client Java Example

This Java example is for Java developers to use and modify when they wish to make a VSAC SVS API call from within their program.

import java.io.IOException;
import java.net.URI;
import java.util.Base64;

import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpHeaders;

public class SvsClient {

	public static void main(String[] args) throws IOException {

		String svsServerBase = "https://vsac.nlm.nih.gov/vsac/svs/";
		String username = "";
		String password = "d4c9d78b-83dc-499e-ae27-947cc00fb438"; // Assign an API key to password

		HttpClient client = HttpClientBuilder.create().build();

		try {
			
			String valueToEncode = username + ":" + password;
		    String basicAuthHeader =  "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes());		
		    
		    
			String testUrl = svsServerBase + "RetrieveMultipleValueSets";

			HttpGet httpGet = new HttpGet(testUrl);
			URI uri = new URIBuilder(httpGet.getURI()).addParameter("id", "2.16.840.1.113762.1.4.1029.256").build(); // VSAC OID example
			httpGet.setURI(uri);
			
			httpGet.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader);

			HttpResponse response = client.execute(httpGet);
			String responseString = EntityUtils.toString(response.getEntity());
			System.out.println(responseString);

			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Last Reviewed: September 7, 2023