Skip to content

Commit de68fd3

Browse files
committed
add code snippets for pagination
1 parent 5b7ff22 commit de68fd3

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const json = `{
2+
"meta": {
3+
"next": "dW5kZWZpbmVkOjQwOTczNTgxNTg=",
4+
"previous": "null",
5+
"perPage": 49
6+
}
7+
}`;
8+
9+
export {json};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const sh = `#!/bin/sh
2+
use_cursor="true"
3+
perPage="50"
4+
url="https://api.paystack.co/transaction?use_cursor=$use_cursor&perPage=$perPage"
5+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
6+
7+
curl "$url" -H "$authorization" -X GET`
8+
9+
const js = `const https = require('https')
10+
11+
const use_cursor = true;
12+
const perPage = 50;
13+
const options = {
14+
hostname: 'api.paystack.co',
15+
port: 443,
16+
path: \`/transaction?use_cursor=\${use_cursor}&perPage=\${perPage}\`,
17+
method: 'GET',
18+
headers: {
19+
Authorization: 'Bearer SECRET_KEY'
20+
}
21+
}
22+
23+
https.request(options, res => {
24+
let data = ''
25+
26+
res.on('data', (chunk) => {
27+
data += chunk
28+
});
29+
30+
res.on('end', () => {
31+
console.log(JSON.parse(data))
32+
})
33+
}).on('error', error => {
34+
console.error(error)
35+
})`
36+
37+
const php = `<?php
38+
$use_cursor = true;
39+
$perPage = 50;
40+
$curl = curl_init();
41+
42+
curl_setopt_array($curl, array(
43+
CURLOPT_URL => "https://api.paystack.co/transaction?use_cursor=$use_cursor&perPage=$perPage",
44+
CURLOPT_RETURNTRANSFER => true,
45+
CURLOPT_ENCODING => "",
46+
CURLOPT_MAXREDIRS => 10,
47+
CURLOPT_TIMEOUT => 30,
48+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
49+
CURLOPT_CUSTOMREQUEST => "GET",
50+
CURLOPT_HTTPHEADER => array(
51+
"Authorization: Bearer SECRET_KEY",
52+
"Cache-Control: no-cache",
53+
),
54+
));
55+
56+
$response = curl_exec($curl);
57+
$err = curl_error($curl);
58+
59+
curl_close($curl);
60+
61+
if ($err) {
62+
echo "cURL Error #:" . $err;
63+
} else {
64+
echo $response;
65+
}
66+
?>`
67+
68+
export {sh, js, php}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const json = `{
2+
"meta": {
3+
"total": 7316,
4+
"total_volume": 397800,
5+
"skipped": 0,
6+
"perPage": 50,
7+
"page": 1,
8+
"pageCount": 147
9+
}
10+
}`
11+
12+
export {json}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const sh = `#!/bin/sh
2+
page="1"
3+
perPage="50"
4+
url="https://api.paystack.co/transaction?page=$page&perPage=$perPage"
5+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
6+
7+
curl "$url" -H "$authorization" -X GET`
8+
9+
const js = `const https = require('https')
10+
11+
const page = 1;
12+
const perPage = 50;
13+
const options = {
14+
hostname: 'api.paystack.co',
15+
port: 443,
16+
path: \`/transaction?page=\${page}&perPage=\${perPage}\`,
17+
method: 'GET',
18+
headers: {
19+
Authorization: 'Bearer SECRET_KEY'
20+
}
21+
}
22+
23+
https.request(options, res => {
24+
let data = ''
25+
26+
res.on('data', (chunk) => {
27+
data += chunk
28+
});
29+
30+
res.on('end', () => {
31+
console.log(JSON.parse(data))
32+
})
33+
}).on('error', error => {
34+
console.error(error)
35+
})`
36+
37+
const php = `<?php
38+
$page = 1;
39+
$perPage = 50;
40+
$curl = curl_init();
41+
42+
curl_setopt_array($curl, array(
43+
CURLOPT_URL => "https://api.paystack.co/transaction?page=$page&perPage=$perPage",
44+
CURLOPT_RETURNTRANSFER => true,
45+
CURLOPT_ENCODING => "",
46+
CURLOPT_MAXREDIRS => 10,
47+
CURLOPT_TIMEOUT => 30,
48+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
49+
CURLOPT_CUSTOMREQUEST => "GET",
50+
CURLOPT_HTTPHEADER => array(
51+
"Authorization: Bearer SECRET_KEY",
52+
"Cache-Control: no-cache",
53+
),
54+
));
55+
56+
$response = curl_exec($curl);
57+
$err = curl_error($curl);
58+
59+
curl_close($curl);
60+
61+
if ($err) {
62+
echo "cURL Error #:" . $err;
63+
} else {
64+
echo $response;
65+
}
66+
?>`
67+
68+
export {sh, js, php}

0 commit comments

Comments
 (0)