Raised This Month: $344 Target: $400
 86%   Almost there!

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


Post New Thread Reply   
 
Thread Tools Display Modes
mrdiega
Junior 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
Junior 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
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 07:57.


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