Skip to content

Commit 2a5b827

Browse files
Add samples for the delete endpoint
1 parent 102d713 commit 2a5b827

12 files changed

Lines changed: 210 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var client = new HttpClient();
2+
var request = new HttpRequestMessage(HttpMethod.Delete, "https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
3+
request.Headers.Add("api-key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
4+
var response = await client.SendAsync(request);
5+
response.EnsureSuccessStatusCode();
6+
Console.WriteLine(await response.Content.ReadAsStringAsync());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var client = new HttpClient();
2+
var request = new HttpRequestMessage(HttpMethod.Delete, "https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
3+
request.Headers.Add("api-key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
4+
var response = await client.SendAsync(request);
5+
response.EnsureSuccessStatusCode();
6+
Console.WriteLine(await response.Content.ReadAsStringAsync());
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import io.github.cdimascio.dotenv.Dotenv;
2+
import java.io.IOException;
3+
import okhttp3.*;
4+
import org.json.JSONObject;
5+
6+
public class DeleteResource {
7+
8+
// Resource UUIDs can be found in the JSON response of POST requests as "outputId".
9+
// Resource UUIDs usually look like this: '0950b9bdf-0465-4d3f-8ea3-d2894f1ae839'.
10+
private static final String FILE_ID =
11+
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // place resource uuid here
12+
13+
// Specify your API key here, or in the environment variable PDFREST_API_KEY.
14+
// You can also put the environment variable in a .env file.
15+
private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
16+
17+
public static void main(String[] args) {
18+
final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load();
19+
try {
20+
final RequestBody requestBody = RequestBody.create("", MediaType.parse("text/plain"));
21+
OkHttpClient client = new OkHttpClient().newBuilder().build();
22+
Request request =
23+
new Request.Builder()
24+
.header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY))
25+
.url("https://api.pdfrest.com/resource/" + FILE_ID)
26+
.method("DELETE", requestBody)
27+
.build();
28+
Response response = client.newCall(request).execute();
29+
System.out.println("Processing Result code " + response.code());
30+
if (response.body() != null && response.body().contentLength() > 0) {
31+
System.out.println(prettyJson(response.body().string()));
32+
}
33+
} catch (IOException e) {
34+
throw new RuntimeException(e);
35+
}
36+
}
37+
38+
private static String prettyJson(String json) {
39+
// https://stackoverflow.com/a/9583835/11996393
40+
return new JSONObject(json).toString(4);
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import io.github.cdimascio.dotenv.Dotenv;
2+
import java.io.IOException;
3+
import okhttp3.*;
4+
import org.json.JSONObject;
5+
6+
public class DeleteResource {
7+
8+
// Resource UUIDs can be found in the JSON response of POST requests as "outputId".
9+
// Resource UUIDs usually look like this: '0950b9bdf-0465-4d3f-8ea3-d2894f1ae839'.
10+
private static final String FILE_ID =
11+
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // place resource uuid here
12+
13+
// Specify your API key here, or in the environment variable PDFREST_API_KEY.
14+
// You can also put the environment variable in a .env file.
15+
private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
16+
17+
public static void main(String[] args) {
18+
final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load();
19+
try {
20+
final RequestBody requestBody = RequestBody.create("", MediaType.parse("text/plain"));
21+
OkHttpClient client = new OkHttpClient().newBuilder().build();
22+
Request request =
23+
new Request.Builder()
24+
.header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY))
25+
.url("https://api.pdfrest.com/resource/" + FILE_ID)
26+
.method("DELETE", requestBody)
27+
.build();
28+
Response response = client.newCall(request).execute();
29+
System.out.println("Processing Result code " + response.code());
30+
if (response.body() != null && response.body().contentLength() > 0) {
31+
System.out.println(prettyJson(response.body().string()));
32+
}
33+
} catch (IOException e) {
34+
throw new RuntimeException(e);
35+
}
36+
}
37+
38+
private static String prettyJson(String json) {
39+
// https://stackoverflow.com/a/9583835/11996393
40+
return new JSONObject(json).toString(4);
41+
}
42+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const axios = require("axios");
2+
3+
let config = {
4+
method: "delete",
5+
maxBodyLength: Infinity,
6+
url: "https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
7+
headers: {
8+
"api-key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
9+
},
10+
};
11+
12+
axios
13+
.request(config)
14+
.then((response) => {
15+
console.log(JSON.stringify(response.data));
16+
})
17+
.catch((error) => {
18+
console.log(error);
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const axios = require("axios");
2+
3+
let config = {
4+
method: "delete",
5+
maxBodyLength: Infinity,
6+
url: "https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
7+
headers: {
8+
"api-key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
9+
},
10+
};
11+
12+
axios
13+
.request(config)
14+
.then((response) => {
15+
console.log(JSON.stringify(response.data));
16+
})
17+
.catch((error) => {
18+
console.log(error);
19+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
$curl = curl_init();
4+
5+
curl_setopt_array($curl, array(
6+
CURLOPT_URL => 'https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
7+
CURLOPT_RETURNTRANSFER => true,
8+
CURLOPT_ENCODING => '',
9+
CURLOPT_MAXREDIRS => 10,
10+
CURLOPT_TIMEOUT => 0,
11+
CURLOPT_FOLLOWLOCATION => true,
12+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13+
CURLOPT_CUSTOMREQUEST => 'DELETE',
14+
CURLOPT_HTTPHEADER => array(
15+
'api-key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
16+
),
17+
));
18+
19+
$response = curl_exec($curl);
20+
21+
curl_close($curl);
22+
23+
echo $response;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
$curl = curl_init();
4+
5+
curl_setopt_array($curl, array(
6+
CURLOPT_URL => 'https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
7+
CURLOPT_RETURNTRANSFER => true,
8+
CURLOPT_ENCODING => '',
9+
CURLOPT_MAXREDIRS => 10,
10+
CURLOPT_TIMEOUT => 0,
11+
CURLOPT_FOLLOWLOCATION => true,
12+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13+
CURLOPT_CUSTOMREQUEST => 'DELETE',
14+
CURLOPT_HTTPHEADER => array(
15+
'api-key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
16+
),
17+
));
18+
19+
$response = curl_exec($curl);
20+
21+
curl_close($curl);
22+
23+
echo $response;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import requests
2+
3+
url = "https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4+
5+
payload = {}
6+
headers = {
7+
'api-key': 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
8+
}
9+
10+
response = requests.request("DELETE", url, headers=headers, data=payload)
11+
12+
print(response.text)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import requests
2+
3+
url = "https://api.pdfrest.com/resource/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4+
5+
payload = {}
6+
headers = {
7+
'api-key': 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
8+
}
9+
10+
response = requests.request("DELETE", url, headers=headers, data=payload)
11+
12+
print(response.text)

0 commit comments

Comments
 (0)