This repository was archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
send code examples
Fabio Russo edited this page Oct 21, 2021
·
17 revisions
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer apikey");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"uuid": "asdf-ghjk-zxcv-1234",
"type": "log",
"payload": "{\"a\":1,\"b\":\"a sample text\"}",
"level": "info",
"timestamp": new Date(),
"metadata": "{\"metadataliveshere\":\"\"usefulmetadatahere\"}",
"title": "sample log today",
"origin": "backend server #1"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://app.bugreplay.com//api/fullstack/v1/send", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));Or
var axios = require('axios');
var data = JSON.stringify({
"uuid": "asdf-ghjk-zxcv-1234",
"type": "log",
"payload": "{\"a\":1,\"b\":\"a sample text\"}",
"level": "info",
"timestamp": new Date(),
"metadata": "{\"metadataliveshere\":\"\"usefulmetadatahere\"}",
"title": "sample log today",
"origin": "backend server #1"
});
var config = {
method: 'post',
url: 'https://app.bugreplay.com//api/fullstack/v1/send',
headers: {
'Authorization': 'Bearer apikey',
'Content-Type': 'application/json',
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});require "uri"
require "json"
require "net/http"
url = URI("https://app.bugreplay.com//api/fullstack/v1/send")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer apikey"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"uuid": "asdf-ghjk-zxcv-1234",
"type": "log",
"payload": "{\"a\":1,\"b\":\"a sample text\"}",
"level": "info",
"timestamp": (Time.now.to_f * 1000).to_i,
"metadata": "{\"metadataliveshere\":\"\"usefulmetadatahere\"}",
"title": "sample log today",
"origin": "backend server #1"
})
response = https.request(request)
puts response.read_bodypackage main
import (
"fmt"
"time"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://app.bugreplay.com//api/fullstack/v1/send"
method := "POST"
payload := strings.NewReader(`{
"uuid" : "asdf-ghjk-zxcv-1234",
"type" : "log",
"payload" : "{\"a\":1,\"b\":\"a sample text\"}",
"level": "info",
"timestamp" : time.Now().UnixMilli(),
"metadata":"{\"metadataliveshere\":\"\"usefulmetadatahere\"}",
"title" : "sample log today",
"origin":"backend server #1"
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Bearer apikey")
req.Header.Add("Content-Type", "application/json")
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))
}import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)
let parameters = "{\n \"uuid\" : \"asdf-ghjk-zxcv-1234\",\n \"type\" : \"log\",\n \"payload\" : \"{\\\"a\\\":1,\\\"b\\\":\\\"a sample text\\\"}\",\n \"level\": \"info\",\n \"timestamp\" : Date().timeIntervalSince1970*1000,\n \"metadata\":\"{\\\"metadataliveshere\\\":\\\"\\\"usefulmetadatahere\\\"}\",\n \"title\" : \"sample log today\",\n \"origin\":\"backend server #1\"\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://app.bugreplay.com//api/fullstack/v1/send")!,timeoutInterval: Double.infinity)
request.addValue("Bearer apikey", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()import http.client
import json
conn = http.client.HTTPSConnection("app.bugreplay.com")
payload = json.dumps({
"uuid": "asdf-ghjk-zxcv-1234",
"type": "log",
"payload": "{\"a\":1,\"b\":\"a sample text\"}",
"level": "info",
"timestamp": int(round(time.time() * 1000)),
"metadata": "{\"metadataliveshere\":\"\"usefulmetadatahere\"}",
"title": "sample log today",
"origin": "backend server #1"
})
headers = {
'Authorization': 'Bearer apikey',
'Content-Type': 'application/json'
}
conn.request("POST", "//api/fullstack/v1/send", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"uuid\" : \"asdf-ghjk-zxcv-1234\",\n \"type\" : \"log\",\n \"payload\" : \"{\\\"a\\\":1,\\\"b\\\":\\\"a sample text\\\"}\",\n \"level\": \"info\",\n \"timestamp\" : System.currentTimeMillis(),\n \"metadata\":\"{\\\"metadataliveshere\\\":\\\"\\\"usefulmetadatahere\\\"}\",\n \"title\" : \"sample log today\",\n \"origin\":\"backend server #1\"\n}");
Request request = new Request.Builder()
.url("https://app.bugreplay.com//api/fullstack/v1/send")
.method("POST", body)
.addHeader("Authorization", "Bearer apikey")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();Or
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://app.bugreplay.com//api/fullstack/v1/send")
.header("Authorization", "Bearer apikey")
.header("Content-Type", "application/json")
.body("{\n \"uuid\" : \"asdf-ghjk-zxcv-1234\",\n \"type\" : \"log\",\n \"payload\" : \"{\\\"a\\\":1,\\\"b\\\":\\\"a sample text\\\"}\",\n \"level\": \"info\",\n \"timestamp\" : System.currentTimeMillis(),\n \"metadata\":\"{\\\"metadataliveshere\\\":\\\"\\\"usefulmetadatahere\\\"}\",\n \"title\" : \"sample log today\",\n \"origin\":\"backend server #1\"\n}")
.asString();var client = new RestClient("https://app.bugreplay.com//api/fullstack/v1/send");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer apikey");
request.AddHeader("Content-Type", "application/json");
var body = @"{" + "\n" +
@" ""uuid"" : ""asdf-ghjk-zxcv-1234""," + "\n" +
@" ""type"" : ""log""," + "\n" +
@" ""payload"" : ""{\""a\"":1,\""b\"":\""a sample text\""}""," + "\n" +
@" ""level"": ""info""," + "\n" +
@" ""timestamp"" : DateTimeOffset.Now.ToUnixTimeMilliseconds()," + "\n" +
@" ""metadata"":""{\""metadataliveshere\"":\""\""usefulmetadatahere\""}""," + "\n" +
@" ""title"" : ""sample log today""," + "\n" +
@" ""origin"":""backend server #1""" + "\n" +
@"}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);