Raised This Month: $12 Target: $400
 3% 

REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)


Post New Thread Reply   
 
Thread Tools Display Modes
mrdiega
Member
Join Date: Dec 2020
Old 10-04-2021 , 17:18   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
Reply With Quote #111

can i use it with sv_hibernate_when_empty 1?
(plugin !stickers)
mrdiega is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 12-04-2021 , 15:48   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
Reply With Quote #112

Hi, please add "GetDataType". Thanks <3
__________________
kratoss1812 is offline
Stewart Anubis
Junior Member
Join Date: Jul 2020
Old 01-25-2022 , 15:03   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
Reply With Quote #113

Does anyone know how I can convert this "[[["Hola","hello",null,null,10]],null,"en",null,null,null,null,[]]" to "Hola" using #include <ripext> ?

Code:
Handle CreateRequest(char[] input, char[] target)
{
    
    Handle request = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, "http://translate.googleapis.com/translate_a/single");
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "client", "gtx");
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "dt", "t");    
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "sl", "auto");//from en default, so you might wanna add this param too to modify.
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "tl", target);//to desired.. target language
    SteamWorks_SetHTTPRequestGetOrPostParameter(request, "q", input);//input text

    //final url would be something like this  https://translate.googleapis.com/tra...&tl=es&q=hello
    //response example [[["Hola","hello",null,null,10]],null,"en",null,null,null,null,[]]  so we need to parse json on Callback_OnHTTPResponse >  JSON.parse(response)[0][0][0] = Hola
    
    Handle datapack = CreateDataPack();
    WritePackString(datapack, target);
    WritePackString(datapack, input);

    
    SteamWorks_SetHTTPRequestContextValue(request, datapack);
    SteamWorks_SetHTTPCallbacks(request, Callback_OnHTTPResponse);
    return request;
}

public int Callback_OnHTTPResponse(Handle request, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, Handle datapack)
{
	if (!bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
	{	  
		CloseHandle(datapack);		
		return;
	}

	int iBufferSize;
	SteamWorks_GetHTTPResponseBodySize(request, iBufferSize);

	char[] result = new char[iBufferSize];
	SteamWorks_GetHTTPResponseBodyData(request, result, iBufferSize);
	delete request;
	
	char target[3], input[255];
	ResetPack(datapack);
	ReadPackString(datapack, target, 3);
	ReadPackString(datapack, input, 255);
	CloseHandle(datapack);

	PrintToServer(result); // = [[["Hola","hello",null,null,10]],null,"en",null,null,null,null,[]]
}

Last edited by Stewart Anubis; 01-25-2022 at 15:09.
Stewart Anubis is offline
leandro442
Member
Join Date: Sep 2013
Location: Portugal
Old 08-10-2022 , 14:11   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
Reply With Quote #114

hello, I was trying to create a header through ripext on a test site but nothing happens I don't know why, has anyone created a header and did it work? do we have to give some permission or create code type in index.php? to work?
leandro442 is offline
bayshades
Member
Join Date: Sep 2019
Old 11-17-2022 , 22:59   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/06/06)
Reply With Quote #115

Quote:
Originally Posted by digin View Post
i don't know why but after i move to my new VPS the PUT think is not working, always return HTTPStatus_Invalid = 0.

My Old VPS : Plesk Panel (PHP 7.4.20 + Server API FPM/FastCGI)
My New VPS : Cyberpanel (PHP 7.4.20 + Server API LiteSpeed V7.9)

"REST in Pawn" (1.2.3) by Tsunami: Provides HTTP and JSON natives for plugins

i test with Postman it's working, but the plugin always return HTTPStatus_Invalid = 0.

anyone experiencing the same thing?
I am facing with same issue. Does anyone found a way to fix it?
bayshades is offline
foxhound27
AlliedModders Donor
Join Date: Sep 2019
Location: Argentina
Old 03-21-2023 , 15:03   Re: REST in Pawn 1.3 - HTTP client for JSON REST APIs (Updated 2021/08/22)
Reply With Quote #116

amazing, thx
foxhound27 is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 07-18-2023 , 08:22   Re: REST in Pawn Code Examples
Reply With Quote #117

Quote:
Originally Posted by DJ Tsunami View Post
HTTP

Retrieve an item

PHP Code:
#include <sourcemod>
#include <ripext>

public void OnPluginStart()
{
    
HTTPRequest request = new HTTPRequest("https://jsonplaceholder.typicode.com/todos/1");

    
request.Get(OnTodoReceived);
}

void OnTodoReceived(HTTPResponse responseany value)
{
    if (
response.Status != HTTPStatus_OK) {
        
// Failed to retrieve todo
        
return;
    }

    
// Indicate that the response contains a JSON object
    
JSONObject todo view_as<JSONObject>(response.Data);

    
char title[256];
    
todo.GetString("title"titlesizeof(title));

    
PrintToServer("Retrieved todo with title '%s'"title);

This isn't working. it's not even sending the http request. The function OnTodoReceived is called but with a Null response. The HTTP request is not even reaching the server. The extension on the server is running.

edit: The (php-) api (using get paramters) is working. I was able to call it with the Steamworks extention as well. But I need the Json decoding on the response.

Last edited by fragnichtnach; 07-18-2023 at 08:28.
fragnichtnach is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode