SkriptWebAPI

Addon SkriptWebAPI Version 0.1.2

  • 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!

Contributors
faketuna, Rily_
Supported Skript Version
  1. 2.7
Supported Minecraft Versions
  1. 1.13
  2. 1.14
  3. 1.15
  4. 1.16
  5. 1.17
  6. 1.18
  7. 1.19
  8. 1.20
About support:
If you have any requests, bug reports, or just want help from me. Please create Issue on GitHub.
I will not provide support in any platform except GitHub.

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.


Features:

  • Simple HTTP Server
  • Send web request
Install:

Note:
This plugin requires paper server or paper based server.

Requirements:

    • Paper server or paper based server
    • Version 1.13

Installing:
Same as other common addons.

    • Download latest SkriptWebAPI-<Version>.jar from here.
    • Put your downloaded jar to server plugins folder
    • Run and ready to use
Documentation:
Example and syntax has provided in Skript Hub.




Important:
If you use reply effect in not end of event you need exit after reply for avoid error
code_language.skript:
if (something):
    reply %httpexchange% with %string% and response code 200
    exit
if (something2):
    reply %httpexchange% with %string% and response code 202
    exit
You should respond the HTTP request otherwise HTTP clients keep waiting for your response.
code_language.skript:
on receive get request:
    set {_request} to event-request

    if (something):
        reply {_request} with %string% and response code 200
        exit
  
    reply {_request} with %string% and response code 500

Example:

Example script in skunity is may be outdated when the plugin update.
Latest Example script is can be found in here.



code_language.skript:
# Example written in v0.1.0


on script load:
    start http server in port 9000 with context "/"

on script unload:
    stop http server

# ===============================
# Synced web request feature. (This may cause lag spike. If you don't want to happen, please use async web request feature.)
# ===============================


command get:
    trigger:
        set {_request} to new http request with method "GET"
        set {_request}'s target url to "https://httpbin.org/get"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_response} to response of {_request}
        set {_body} to body of {_response}
        broadcast "server: %{_response}'s header value from key "server"%"
        broadcast "Body: %{_body}%"
        broadcast "Status code: %status code of {_response}%"
        broadcast "Request method: %request method of {_response}%"

command delete:
    trigger:
        set {_request} to new http request with method "DELETE"
        set {_request}'s target url to "https://httpbin.org/delete"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_response} to response of {_request}
        set {_body} to body of {_response}
        broadcast "server: %{_response}'s header value from key "server"%"
        broadcast "Body: %{_body}%"
        broadcast "Status code: %status code of {_response}%"
        broadcast "Request method: %request method of {_response}%"

command patch:
    trigger:
        set {_request} to new http request with method "PATCH"
        set {_request}'s target url to "https://httpbin.org/patch"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        set {_response} to response of {_request}
        set {_body} to body of {_response}
        broadcast "server: %{_response}'s header value from key "server"%"
        broadcast "Body: %{_body}%"
        broadcast "Status code: %status code of {_response}%"
        broadcast "Request method: %request method of {_response}%"

command post:
    trigger:
        set {_request} to new http request with method "POST"
        set {_request}'s target url to "https://httpbin.org/post"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        set {_response} to response of {_request}
        set {_body} to body of {_response}
        broadcast "server: %{_response}'s header value from key "server"%"
        broadcast "Body: %{_body}%"
        broadcast "Status code: %status code of {_response}%"
        broadcast "Request method: %request method of {_response}%"

command put:
    trigger:
        set {_request} to new http request with method "PUT"
        set {_request}'s target url to "https://httpbin.org/put"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        set {_response} to response of {_request}
        set {_body} to body of {_response}
        broadcast "server: %{_response}'s header value from key "server"%"
        broadcast "Body: %{_body}%"
        broadcast "Status code: %status code of {_response}%"
        broadcast "Request method: %request method of {_response}%"

command custom-method:
    trigger:
        set {_request} to new http request with method "CUSTOM"
        set {_request}'s target url to "https://domain"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        set {_response} to response of {_request}
        set {_body} to body of {_response}
        broadcast "server: %{_response}'s header value from key "server"%"
        broadcast "Body: %{_body}%"
        broadcast "Status code: %status code of {_response}%"
        broadcast "Request method: %request method of {_response}%"



# ===============================
# Async web request feature.
# ===============================

command asyncget:
    trigger:
        set {_request} to new http request with method "GET"
        set {_request}'s target url to "https://httpbin.org/get"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        send async web request with {_request}

command asyncdelete:
    trigger:
        set {_request} to new http request with method "DELETE"
        set {_request}'s target url to "https://httpbin.org/delete"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        send async web request with {_request}

command asyncpatch:
    trigger:
        set {_request} to new http request with method "PATCH"
        set {_request}'s target url to "https://httpbin.org/patch"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        send async web request with {_request}

command asyncpost:
    trigger:
        set {_request} to new http request with method "POST"
        set {_request}'s target url to "https://httpbin.org/post"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        send async web request with {_request}

command asyncput:
    trigger:
        set {_request} to new http request with method "PUT"
        set {_request}'s target url to "https://httpbin.org/put"
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        send async web request with {_request}

on web request response:
    set {_response} to event-httpresponse
    set {_body} to body of {_response}
    set {_method} to request method of {_response}
    broadcast "server: %{_response}'s header value from key "server"%"
    broadcast "1: %{_body}%"
    broadcast "2: %status code of {_response}%"
    broadcast "3: %request method of {_response}%"



# ===============================
# Http server feature.
# ===============================

on http request received:
    set {_request} to event-httpexchange
    set {_method} to http request method of {_request}
    set {_body} to http request body of {_request}
    set {_userAgent} to http request {_request} request header value from key "User-Agent"
    set {_path} to http request context path of {_request}
    broadcast "HTTP REQUEST!"
    broadcast "METHOD: %{_method}%"
    broadcast "BDOY: %{_body}%"
    broadcast "UA: %{_userAgent}%"
    broadcast "Context: %{_path}%"
    set http response {_request}'s header "Custom" to "Custom header"
    set http response {_request}'s header "Invisible" to "This header should not be visible because will be deleted after set."
    remove http response {_request}'s header "Invisible"

    set {_returnBody} to ""

    if {_method} is "DELETE":
        set {_returnBody} to "{""method"":""DELETE""}"

    if {_method} is "GET":
        set {_returnBody} to "{""method"":""GET""}"

    if {_method} is "PATCH":
        set {_returnBody} to "{""method"":""PATCH""}"

    if {_method} is "POST":
        set {_returnBody} to "{""method"":""POST""}"

    if {_method} is "PUT":
        set {_returnBody} to "{""method"":""PUT""}"

    broadcast "RETURN BODY: %{_returnBody}%"
    if {_returnBody} is not "":
        reply {_request} with body {_returnBody} and response code 200
    else:
      # This will reply 500 without body
        reply {_request}


command testreq <string> <string>:
    trigger:
        set {_request} to new http request with method arg-1
        set {_request}'s target url to arg-2
        set {_request}'s header "Custom" to "Test"
        set {_request}'s header "Content-Type" to "application/json"
        set {_request}'s header "User-Agent" to "SkriptWebAPI/0.1.0"
        set {_request}'s body to "{""json"":""test""}"
        send async web request with {_request}

Todo:
Todo is found in my github readme.

Contributors:
Rily_: Wrote the addon icon.
Author
faketuna
Downloads
710
Views
1,272
First release
Last update
Rating
3.00 star(s) 2 ratings

Latest updates

  1. Version 0.1.2 | Bug fix and new expression

    What's Changed * Fix: java.io.IOException: too many bytes to write to stream error by faketuna...
  2. Version 0.1.1 | Context path fix in HTTP Server

    Fix HTTP Server context path didn't set correctly #11
  3. New syntax, PATCH method and Full plugin rewrite

    Caution This version only supports Skript 2.7.3 or higher and Minecraft version 1.13 or higher...

Latest reviews

I really want to give this addon a 5 star rating, but it's really poorly made, most of the things I tried didn't work and I tried a lot of things out. I know that this addon probably won't get any updates, so if you have a addon that is similar to this one please reply, but if the developers decide to fix the addon it's a easy 5 stars!
F
faketuna
Create Issue on GitHub please.
Hello, there. contact me when you are online, I want help you with our project, cause i working on teplate system for skript