Skip to content

Instantly share code, notes, and snippets.

@paulwababu
Created December 2, 2022 10:35
Show Gist options
  • Save paulwababu/753a9c405df95af9d684cb3b352a8196 to your computer and use it in GitHub Desktop.
Save paulwababu/753a9c405df95af9d684cb3b352a8196 to your computer and use it in GitHub Desktop.
Testing PESAPEDIA API
var client = new RestClient("https://pesapedia.co.ke/api/v2/hello");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
request.AlwaysMultipartFormData = true;
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
curl --location --request GET 'https://pesapedia.co.ke/api/v2/hello' \
--header 'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
var headers = {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
};
var request = http.MultipartRequest('GET', Uri.parse('https://pesapedia.co.ke/api/v2/hello'));
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://pesapedia.co.ke/api/v2/hello"
method := "GET"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
var formdata = new FormData();
var requestOptions = {
method: 'GET',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://pesapedia.co.ke/api/v2/hello", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var form = new FormData();
var settings = {
"url": "https://pesapedia.co.ke/api/v2/hello",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
// WARNING: For GET requests, body is set to null by browsers.
var data = new FormData();
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://pesapedia.co.ke/api/v2/hello");
xhr.setRequestHeader("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
xhr.send(data);
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://pesapedia.co.ke/api/v2/hello',
'headers': {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
},
formData: {
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
var config = {
method: 'get',
url: 'https://pesapedia.co.ke/api/v2/hello',
headers: {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e',
...data.getHeaders()
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'GET',
'hostname': 'pesapedia.co.ke',
'path': '/api/v2/hello',
'headers': {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
var unirest = require('unirest');
var req = unirest('GET', 'https://pesapedia.co.ke/api/v2/hello')
.headers({
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
})
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://pesapedia.co.ke/api/v2/hello',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://pesapedia.co.ke/api/v2/hello"
payload={}
files={}
headers = {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
}
response = requests.request("GET", url, headers=headers, data=payload, files=files)
print(response.text)
library(httr)
headers = c(
'Authorization' = 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
)
res <- VERB("GET", url = "https://pesapedia.co.ke/api/v2/hello", add_headers(headers), encode = 'multipart')
cat(content(res, 'text'))
library(RCurl)
headers = c(
"Authorization" = "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
)
res <- getURL("https://pesapedia.co.ke/api/v2/hello", .opts=list(httpheader = headers, followlocation = TRUE))
cat(res)
require "uri"
require "net/http"
url = URI("https://pesapedia.co.ke/api/v2/hello")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
form_data = []
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
http --ignore-stdin --form --follow --timeout 3600 GET 'https://pesapedia.co.ke/api/v2/hello' \
\
Authorization:'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
wget --no-check-certificate --quiet \
--method GET \
--timeout=0 \
--header 'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e' \
'https://pesapedia.co.ke/api/v2/hello'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment