1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Addon SkriptWebAPI 0.0.3

Provides Web API server feature and Web request feature.

  1. faketuna
    Contributors:
    faketuna, Rily_
    Supported Minecraft Versions:
    • 1.19
    Addon in alpha:
    This Addon is in alpha, so cause probrems please use at your own risk.


    Also this addon is includes missing features and functions, because created for my personal usage.
    If you have any requests, please submit an issue on Github.
    I will not provide any support in skunity review.

    Features:
    Web API Server feature:
    • Handle DELETE, GET, POST, PUT request.
    Web request feature:
    • Send DELETE, GET, POST, PUT request.
    Install:

    Note:

    • Current version (0.0.3) is can only work with paper server. Im plan to make it work with Spigot in the future.
    • Current version (0.0.3) is only run with Minecraft version 1.19.3. Older version is supporting soon.

    Requirements:

    • Paper server
    • Version 1.19.3

    Installing:

    Same as other common addons.
    1. Download SkriptWebAPI-<Version>.jar from here. Lager number mean recent.
    2. Put your downloaded jar to server plugins folder
    3. Run and ready to use
    Documentation:
    Example and syntax has provided in Skript Hub.

    [​IMG]


    Important:
    If you use reply effect in if statement, you need exit after reponse for avoid error
    Code (Skript):
    1. if (something):
    2.    reply %httpexchange% with body %string% and response code 200
    3.    exit
    Also you need reply %httpexchange% as not found in last line of event

    Code (Skript):
    1. on receive get request:
    2.    set {_request} to event-request
    3.  
    4.    if (something):
    5.        reply {_request} with body %string% and response code 200
    6.        exit
    7.  
    8.    reply {_request} as not found
    9.  
    Example:

    Example script is may be outdated when the plugin update.
    the latest Example script is can be found here.



    Code (Skript):
    1. # Written in plugin version 0.0.3
    2.  
    3. on skript load:
    4.    start http server in port 8080
    5.  
    6. on skript unload:
    7.    stop http server
    8.  
    9. # ==== Web request feature ====
    10.  
    11. command get:
    12.    trigger:
    13.        set {_header} to blank header
    14.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    15.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    16.        set {_header}'s properties "Custom" to "Custom header"
    17.        set {_response} to response of get request to "http://httpbin.org/get" with header {_header}
    18.        broadcast {_response}'s response code
    19.        broadcast {_response}'s response body
    20.        broadcast {_response}'s response header "Date"
    21.        broadcast "response: %{_response}'s response body%"
    22.  
    23.  
    24. command put:
    25.    trigger:
    26.        set {_header} to blank header
    27.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    28.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    29.        set {_header}'s properties "Custom" to "Custom header"
    30.        set {_response} to response of put request to "http://httpbin.org/put" with header {_header} and body "{""json"":""body""}"
    31.        broadcast "response: %{_response}'s response body%"
    32.  
    33.  
    34. command post:
    35.    trigger:
    36.        set {_header} to blank header
    37.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    38.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    39.        set {_header}'s properties "Custom" to "Custom header"
    40.        set {_response} to response of post request to "http://httpbin.org/post" with header {_header} and body "{""json"":""body""}"
    41.        broadcast "response: %{_response}'s response body%"
    42.  
    43.  
    44. command delete:
    45.    trigger:
    46.        set {_header} to blank header
    47.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    48.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    49.        set {_header}'s properties "Custom" to "Custom header"
    50.        set {_response} to response of delete request to "http://httpbin.org/delete" with header {_header} and body "{""json"":""body""}"
    51.        broadcast "response: %{_response}'s response body%"
    52.  
    53. # ==== Async web request feature ====
    54.  
    55. command asyncget:
    56.    trigger:
    57.        set {_header} to blank header
    58.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    59.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    60.        set {_header}'s properties "Custom" to "Custom header"
    61.        send get request to "http://httpbin.org/get"
    62.  
    63. on get web request response:
    64.    set {_response} to event-connection
    65.    broadcast {_response}'s response code
    66.    broadcast {_response}'s response body
    67.    broadcast {_response}'s response header "Date"
    68.  
    69.  
    70. command asyncput:
    71.    trigger:
    72.        set {_header} to blank header
    73.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    74.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    75.        set {_header}'s properties "Custom" to "Custom header"
    76.        send put request to "http://httpbin.org/put" with header {_header} and body "{""json"":""body""}"
    77.        
    78. on put web request response:
    79.    set {_response} to event-connection
    80.    broadcast {_response}'s response code
    81.    broadcast {_response}'s response body
    82.    broadcast {_response}'s response header "Date"
    83.  
    84.  
    85. command asyncpost:
    86.    trigger:
    87.        set {_header} to blank header
    88.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    89.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    90.        set {_header}'s properties "Custom" to "Custom header"
    91.        send post request to "http://httpbin.org/post" with header {_header} and body "{""json"":""body""}"
    92.  
    93. on post web request response:
    94.    set {_response} to event-connection
    95.    broadcast {_response}'s response code
    96.    broadcast {_response}'s response body
    97.    broadcast {_response}'s response header "Date"
    98.  
    99.  
    100. command asyncdelete:
    101.    trigger:
    102.        set {_header} to blank header
    103.        set {_header}'s properties "Content-Type" to "applicaiton/json"
    104.        set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    105.        set {_header}'s properties "Custom" to "Custom header"
    106.        send delete request to "http://httpbin.org/delete" with header {_header} and body "{""json"":""body""}"
    107.  
    108. on delete web request response:
    109.    set {_response} to event-connection
    110.    broadcast {_response}'s response code
    111.    broadcast {_response}'s response body
    112.    broadcast {_response}'s response header "Date"
    113.  
    114. # ==== API Server feature ====
    115.  
    116. on receive get request:
    117.    set {_request} to event-request
    118.    set {_path} to {_request}'s path
    119.    set {_body} to ""
    120.  
    121.    if ({_path} is "/user"):
    122.        set {_user} to number of all players
    123.        set {_body} to "{""user"":""%{_user}%""}"
    124.        set {_request}'s response header "Content-Type" to "application/json"
    125.        reply {_request} with body {_body} and response code 200
    126.        exit
    127.  
    128.    reply {_request} as not found
    129.  
    130. on receive put request:
    131.    set {_request} to event-request
    132.    broadcast {_request}'s path
    133.    set {_request} to event-request
    134.    set {_path} to {_request}'s path
    135.    set {_body} to ""
    136.  
    137.  
    138.    if ({_path} is "/send"):
    139.        set {_user} to {_request}'s request header properties "User" parsed as offline player
    140.        set {_message} to {_request}'s request header properties "Message"
    141.        
    142.        if ({_user} is online):
    143.            send {_message} to {_user}
    144.            set {_body} to "{""sent"":true}"
    145.        else:
    146.            set {_body} to "{""sent"":false}"
    147.        
    148.        set {_request}'s response header "Content-Type" to "application/json"
    149.        reply {_request} with body {_body} and response code 200
    150.        exit
    151.  
    152.    reply {_request} as not found
    153.  
    154.  
    155. on receive post request:
    156.    set {_request} to event-request
    157.    set {_path} to {_request}'s path
    158.    set {_body} to ""
    159.  
    160.    if ({_path} is "/add-value"):
    161.        set {_listName} to {_request}'s request header properties "List"
    162.        set {_value} to {_request}'s request header properties "Value"
    163.    
    164.        if ({%{_listName}%::*} is not set):
    165.            set {_body} to "{""list"":""not found""}"
    166.            reply {_request} with body {_body} and response code 404
    167.            exit
    168.        
    169.        else if ({_value} is not set):
    170.            set {_body} to "{""error"":""Value not provided""}"
    171.            reply {_request} with body {_body} and response code 400
    172.            exit
    173.        
    174.        else:
    175.            add {_value} to {%{_listName}%::*}
    176.            set {_body} to "{""list"":""added""}"
    177.  
    178.        set {_request}'s response header "Content-Type" to "application/json"
    179.        reply {_request} with body {_body} and response code 200
    180.        exit
    181.        
    182.    reply {_request} as not found
    183.  
    184. on receive delete request:
    185.    set {_request} to event-request
    186.    set {_path} to {_request}'s path
    187.    set {_body} to ""
    188.  
    189.    if ({_path} is "/delete-variable"):
    190.        set {_variableName} to {_request}'s request header properties "VariableName"
    191.  
    192.  
    193.        if ({%{_variableName}%} is not set):
    194.            set {_body} to "{""variable"":""not found""}"
    195.            reply {_request} with body {_body} and response code 404
    196.            exit
    197.        else:
    198.            delete {%{_variableName}%}
    199.            set {_body} to "{""variable"":""removed""}"
    200.  
    201.        set {_request}'s response header "Content-Type" to "application/json"
    202.        reply {_request} with body {_body} and response code 200
    203.        exit
    204.  
    205.  
    206.    reply {_request} as not found
    Todo:
    Todo is found in my github readme.

    Contributors:
    Rily_: Wrote the addon icon.