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.

SkriptWebAPI

Discussion in 'Addon Releases' started by faketuna, Jan 1, 2023.

  1. faketuna

    faketuna New Member

    Joined:
    Dec 29, 2022
    Messages:
    0
    Likes Received:
    0
    Addon in alpha:
    This Addon is in alpha, so cause probrems please use at your own risk.


    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.1) is can only work with paper server. Im plan to make it work with Spigot in the future.
    • Current version (0.0.1) is only run with Minecraft version 1.19.3. Older version is supporting soon.
    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:

    Code (Skript):
    1. # Written in plugin version 0.0.1
    2.  
    3. on skript load:
    4.     start http server in port 8080
    5.  
    6. on skript unload:
    7.     stop http server
    8.  
    9. command get:
    10.     trigger:
    11.         set {_header} to blank header
    12.         set {_header}'s properties "Content-Type" to "applicaiton/json"
    13.         set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    14.         set {_header}'s properties "Custom" to "Custom header"
    15.         set {_a} to response of get request to "http://httpbin.org/get" with header {_header}
    16.         broadcast "response: %{_a}%"
    17.  
    18. command put:
    19.     trigger:
    20.         set {_header} to blank header
    21.         set {_header}'s properties "Content-Type" to "applicaiton/json"
    22.         set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    23.         set {_header}'s properties "Custom" to "Custom header"
    24.         set {_a} to response of put request to "http://httpbin.org/put" with header {_header} and body "{""json"":""value""}"
    25.         broadcast "response: %{_a}%"
    26.  
    27. command post:
    28.     trigger:
    29.         set {_header} to blank header
    30.         set {_header}'s properties "Content-Type" to "applicaiton/json"
    31.         set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    32.         set {_header}'s properties "Custom" to "Custom header"
    33.         set {_a} to response of post request to "http://httpbin.org/post" with header {_header} and body "{""json"":""value""}"
    34.         broadcast "response: %{_a}%"
    35.  
    36. command delete:
    37.     trigger:
    38.         set {_header} to blank header
    39.         set {_header}'s properties "Content-Type" to "applicaiton/json"
    40.         set {_header}'s properties "User-Agent" to "SkriptWebAPI/0.0.1"
    41.         set {_header}'s properties "Custom" to "Custom header"
    42.         set {_a} to response of delete request to "http://httpbin.org/delete" with header {_header} and body "{""json"":""value""}"
    43.         broadcast "response: %{_a}%"
    44.  
    45. on receive get request:
    46.     set {_request} to event-request
    47.     set {_path} to event-path parsed as text
    48.  
    49.     if ({_path} is "/user"):
    50.         set {_user} to number of all players
    51.         set {_body} to "{""user"":""%{_user}%""}"
    52.         set {_request}'s response header "Content-Type" to "application/json"
    53.         reply {_request} with body {_body} and response code 200
    54.         exit
    55.  
    56.     reply {_request} as not found
    57.  
    58. on receive put request:
    59.     set {_request} to event-request
    60.     set {_path} to event-path parsed as text
    61.  
    62.  
    63.     if ({_path} contains "/send/"):
    64.         set {_query} to {_path}
    65.         replace "/send/" in {_query} with ""
    66.         set {_query::*} to split {_query} at "/"
    67.  
    68.         set {_user} to {_query::1} parsed as offline player
    69.         set {_message} to {_query::2}
    70.  
    71.         if ({_user} is online):
    72.             send {_message} to {_user}
    73.             set {_body} to "{""sent"":true}"
    74.         else:
    75.             set {_body} to "{""sent"":false}"
    76.  
    77.         set {_request}'s response header "Content-Type" to "application/json"
    78.         reply {_request} with body {_body} and response code 200
    79.         exit
    80.  
    81.     reply {_request} as not found
    82.  
    83.  
    84. on receive post request:
    85.     set {_request} to event-request
    86.     set {_path} to event-path parsed as text
    87.     set {_body} to ""
    88.  
    89.     # If URI is http://domain/add-value/list/value
    90.     if ({_path} contains "/add-value/"):
    91.         set {_query} to {_path}
    92.         replace "/add-value/" in {_query} with ""
    93.         set {_query::*} to split {_query} at "/"
    94.  
    95.  
    96.         if (size of {_query::*} >= 3):
    97.             set {_body} to "{""error"":""To may arguments""}"
    98.             reply {_request} with body {_body} and response code 400
    99.             exit
    100.  
    101.         # {_query::1} is "list"
    102.         # {_query::2} is "value"
    103.  
    104.         if ({%{_query::1}%::*} is not set):
    105.             set {_body} to "{""list"":""not found""}"
    106.         else:
    107.             # add "value" to {list::*}
    108.             add {_query::2} to {%{_query::1}%::*}
    109.             set {_body} to "{""list"":""added""}"
    110.  
    111.         set {_request}'s response header "Content-Type" to "application/json"
    112.         reply {_request} with body {_body} and response code 200
    113.         exit
    114.  
    115.     reply {_request} as not found
    116.  
    117. on receive delete request:
    118.     set {_request} to event-request
    119.     set {_path} to event-path parsed as text
    120.  
    121.     if ({_path} contains "/delete-variable/"):
    122.         set {_query} to {_path}
    123.         replace "/delete-variable/" in {_query} with ""
    124.         set {_query::*} to split {_query} at "/"
    125.  
    126.         if ({%{_query::1}%} is not set):
    127.             set {_body} to "{""variable"":""not found""}"
    128.         else:
    129.             delete {%{_query::1}%}
    130.             set {_body} to "{""variable"":""removed""}"
    131.  
    132.         set {_request}'s response header "Content-Type" to "application/json"
    133.         reply {_request} with body {_body} and response code 200
    134.         exit
    135.  
    136.  
    137.     reply {_request} as not found
    Todo:
    Todo is found in my github readme.

    Contributors:
    Rily_: wrote the addon icon.
     

Share This Page

Loading...