<pre class="brush:java">
// The import java URL connection to the resource. URL url = new URL("http://localhost:8984/rest/factbook")net.*; // Establish the connection to the URL. HttpURLConnection conn = (HttpURLConnection) urlimport org.openConnection(); // Set as DELETE requestbasex. connutil.setRequestMethod("DELETE")*;
public final class RESTExample { public static void main(String[] args) throws Exception { // The java URL connection to the resource. URL url = new URL("http://localhost:8984/rest/factbook"); // Establish the connection to the URL. HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // Set as DELETE request. conn.setRequestMethod("DELETE"); // User and password. String user = "bob"; String pw ="alice"; // Encode user name and password pair with a base64 implementation. String encoded = Base64.encode(user + ":" + pw); // Basic access authentication header to connection request. conn.setRequestProperty("Authorization", "Basic " + encoded); // Print the HTTP response code. System.out.println("HTTP response: " + conn.getResponseCode()); // Close connection. conn.disconnect(); }}
</pre>