Vzurxy

syn.request

Jul 7th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. -- Specific functions documentation
  2. syn.request:
  3. (very epic function btw)
  4. Standard example:
  5.  
  6. local Response = syn.request(
  7.    {
  8.       Url = "ExampleURL";
  9.       Method = "POST";
  10.       Headers = {
  11.          ["Content-Type"] = "application/json"; -- When sending JSON, add this!
  12.       };
  13.       Body = game:GetService("HttpService"):JSONEncode({hello = "world"});
  14. )
  15. for i, v in pairs(Response) do
  16.    print(i, v)
  17.    if type(v) == "table" then
  18.       for i2, v2 in pairs(v) do
  19.          warn(i2, v2)
  20.       end
  21.    end
  22. end
  23.  
  24. Discord Webhook example:
  25. local Data = {
  26.    ["username"] = "Cool Webhook";
  27.    ["content"] = "This is a super cool webhook!";
  28. }
  29. Data = game:GetService("HttpService"):JSONEncode(Data)
  30. local Response = nil
  31. Response = syn.request(
  32.    {
  33.       Url = "WebhookURLhere";
  34.       Method = "POST";
  35.       Headers = {
  36.          ["Content-Type"] = "application/json";
  37.       };
  38.       Body = Data;
  39.    }
  40. )
  41. repeat wait() until Response ~= nil
  42. if Response.Success then
  43.    game:GetService("StarterGui"):SetCore("SendNotification", {
  44.       Title = "Epic!";
  45.       Text = "Sent the webhook shit!";
  46.    })
  47. elseif not Response.Success then
  48.    game:GetService("StarterGui"):SetCore("SendNotification", {
  49.       Title = "Oof!";
  50.       Text = "Failed to send the webhook shit!";
  51.    })
  52. end
Add Comment
Please, Sign In to add comment