SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 09/05/2018, 08:28 PM   #21
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,885
Reputation: 1443
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Quote:
Originally Posted by AdrianGraber View Post
But what to do when you want to recieve them without pinging the server constantly?
That's what WebSockets are designed for - that gives you a bidirectional data flow mechanism where both ends can push data and trigger interrupts on the opposite end. For this you'd create a WebSocket with `WebSocketClient` which would bind that WebSocket to a callback event - your WebSocket server can then pipe data to the gamemode which would call the callback. You can also send data to the web server via `WebSocketSend`. See an example in the unit tests: https://github.com/Southclaws/pawn-r....pwn#L173-L231

I did also recently update the Redis plugin to use the pub/sub mechanism so that is also a viable option if you want to have multiple consumers or multiple senders of a particular communication channel.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 10/05/2018, 10:14 PM   #22
AdrianGraber
Big Clucker
 
AdrianGraber's Avatar
 
Join Date: Mar 2013
Location: Germany
Posts: 97
Reputation: 102
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Quote:
Originally Posted by [HLF]Southclaw View Post
That's what WebSockets are designed for - that gives you a bidirectional data flow mechanism where both ends can push data and trigger interrupts on the opposite end. For this you'd create a WebSocket with `WebSocketClient` which would bind that WebSocket to a callback event - your WebSocket server can then pipe data to the gamemode which would call the callback. You can also send data to the web server via `WebSocketSend`. See an example in the unit tests: https://github.com/Southclaws/pawn-r....pwn#L173-L231

I did also recently update the Redis plugin to use the pub/sub mechanism so that is also a viable option if you want to have multiple consumers or multiple senders of a particular communication channel.
Oh, I didn't noticed that the plugin already supports WebSockets, my bad. I think for most things WebSockets might do the job then.

For things that only need simple messages back and forth, it seems this is pretty much the best solution available at the moment, well done.
AdrianGraber is offline   Reply With Quote
Old 17/05/2018, 01:35 PM   #23
pawnoholic
Big Clucker
 
Join Date: Oct 2017
Posts: 70
Reputation: 3
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Is it possible to implement HTTP authentication with Rest API?
__________________
GitHub: @pawnoholic
pawnoholic is offline   Reply With Quote
Old 17/05/2018, 03:36 PM   #24
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,885
Reputation: 1443
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Quote:
Originally Posted by pawnoholic View Post
Is it possible to implement HTTP authentication with Rest API?
Yes you can either pass the key as a query `?key=123` or add it as a HTTP header.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 28/05/2018, 04:59 PM   #25
DragonStone
Little Clucker
 
Join Date: Mar 2017
Posts: 3
Reputation: 0
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

First of all, thats a really nice plugin.
Iam building my backend with node.js and mongodb right now.
But i have encountered 2 Problem.
In your example you retrieve the length of the ArrayObject with JsonArrayLength, well i get a "file or function not found" error
PHP Code:
[debugRun time error 19"File or function is not found"
[debug]  JsonArrayLength 
Here is the corresponding code

PHP Code:
    new Node:skinListlength;

    
JsonGetArray(node"zivi_skins"skinList);
    
JsonArrayLength(skinListlength);

    for(new 
ilength; ++i) {
        new 
Node:skinsID;

        
JsonArrayObject(skinListiskin);
        
JsonGetInt(skin"skin_id"sID);

        
printf("s_id %d"sID);
    } 
I used your samctpl tool to get the plugin.
The data i retrieve from the Rest-API is valid, because if i replace the length variable with a fixed length it works without a problem.

Second problem or better say questions is, how dou you retrieve the data from a simple Number or String Array like
[1, 2, 3, 4]. I didnt realy find something in your examples or i just missed the corresponding one.
Thanks
DragonStone is offline   Reply With Quote
Old 28/05/2018, 05:20 PM   #26
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,885
Reputation: 1443
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Nice choice! I've been using MongoDB for a SA:MP backend with this plugin too - though my intermediate API is written in Go.

So I've actually forgotten to implement the JsonArrayLength function (sorry!) so I will get that added either tonight or tomorrow morning.

As for getting elements of an array out, these are the functions you need. While iterating an array, you first use JsonArrayObject to get the node that contains the element. Then you convert the output node to a primitive type with JsonGetNodeInt.

I know that workflow is very janky and I'll add some functions to directly convert an array index to a specific type.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 28/05/2018, 06:01 PM   #27
DragonStone
Little Clucker
 
Join Date: Mar 2017
Posts: 3
Reputation: 0
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Thanks for the fast reply.

Gonna work with static lengths for the array for one day xD.
And thanks for the hint with the array.
DragonStone is offline   Reply With Quote
Old 29/05/2018, 11:07 AM   #28
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,885
Reputation: 1443
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Implemented JsonArrayLength in 0.5.0:

https://github.com/Southclaws/pawn-r...ases/tag/0.5.0
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 29/05/2018, 05:50 PM   #29
DragonStone
Little Clucker
 
Join Date: Mar 2017
Posts: 3
Reputation: 0
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Thanks for the fast fix.

//edit
A little bit early to celebrate.
Still got the file or function not found exception.
Maybe i did something wrong dunno.
First i tried it just with ensure commands in sampctl, which did not resolve the error,
then i removed the corresponding files for your pawn-requests plugin, so the dependencies get downloaded again.
After that i tried to manually add them with the release from github.
All those 3 Methods didnt solve the error for me.
I checked if i made a typo but everything looks ok.
Not sure if i did something wrong while trying to update the plugin in my dependencies.
Also tried it with a clean gamemode.

Last edited by DragonStone; 29/05/2018 at 06:26 PM.
DragonStone is offline   Reply With Quote
Old 29/05/2018, 07:17 PM   #30
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,885
Reputation: 1443
Default Re: HTTP(S) Requests+JSON Plugin - Make HTTP(S) Requests with JSON

Quote:
Originally Posted by DragonStone View Post
Thanks for the fast fix.

//edit
A little bit early to celebrate.
Still got the file or function not found exception.
Maybe i did something wrong dunno.
First i tried it just with ensure commands in sampctl, which did not resolve the error,
then i removed the corresponding files for your pawn-requests plugin, so the dependencies get downloaded again.
After that i tried to manually add them with the release from github.
All those 3 Methods didnt solve the error for me.
I checked if i made a typo but everything looks ok.
Not sure if i did something wrong while trying to update the plugin in my dependencies.
Also tried it with a clean gamemode.
That actually sounds like *another* bug of mine (sorry!) that's being tracked here: https://github.com/Southclaws/sampctl/issues/167

What you need to do is delete the plugin folder in ~/.samp/plugins/ (where ~ is your user folder, if on Windows that's C:\Users\YourName)

In future, always use a version constraint when working with plugins, for example:

sampctl package install Southclaws/pawn-requests:0.6.0

This will be a requirement of sampctl in the next version - only for plugin dependencies because of how sampctl gets version information from GitHub.

-

Oh and 0.6.0 just released:

- Added a lot of error checks that should have been implemented earlier. JsonGet* functions will no longer crash on invalid key names but instead return 2 to indicate the error.

- Implemented JsonParse function for parsing a string of JSON into a Node: object.

- Implemented JsonNodeType which will return the type of the given Node: object.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSON and SAMP HTTP davidbull Scripting Help 0 05/09/2016 06:07 AM
[Plugin] SAMPSON - A JSON plugin for SA-MP KingHual Plugin Development 25 15/08/2016 04:40 PM
[HELP] Vehicles.json don't load Stefand Scripting Help 1 21/02/2012 02:19 PM
HTTP() callback won't fire, + server crash using HTTP() KoczkaHUN Bug Reports 6 14/12/2011 09:35 AM
vehicles.json help plz sherlock Server Support 3 02/01/2011 12:41 PM


All times are GMT. The time now is 08:17 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.