- Supported Minecraft Versions
- 1.7
- 1.8
- 1.9
- 1.10
- 1.11
Reqn is an HTTP request library for Skript 2.X.
Documentation/Source - Releases
Quickstart
code_language.skript:
# Send a get request to a url. The protocol (http or https) is required.
send a request to "http://example.com"
# Send a request using a different HTTP method.
send a "put" request to "http://example.com"
# Send a request with headers and a body. They are both optional.
send a "post" request to "http://example.com" with the headers "Authorization: Token", and "Content-Type: application/json" and the body "{""body"":""don't forget to escape your quotes!""}"
# They can be in any order, too.
send a "post" request to "http://example.com" with the body "{""body"":""don't forget to escape your quotes!""}" and the headers "Authorization: Token", and "Content-Type: application/json"
# Access the last response.
set {_resp} to the last http response
# Access the response code
set {_code} to {_resp}'s status code
# Access the headers of a response.
set {_headers::*} to {_resp}'s headers
# Or just a specific header. Capitalization matters with header names.
set {_length} to {_resp}'s "Content-Length" header
# Access the body of a response.
set {_body} to {_resp}'s body
More features (such as JSON escaping) and additional syntax can be found in the documentation.
FAQ
Will requests cause my server to freeze?
No. Unlike skQuery's text from url, processing is done on a separate thread. This also delays the event, meaning you can't set event values after making a request.
Will last HTTP response change if multiple requests complete at the same time?
As long as you retrieve the last HTTP response immediately after making the request (without waiting), there is no chance of responses being mixed up. It's good practice to save the response to a variable immediately and using the variable instead if you intend on using the last HTTP response.
Can I accept compressed content?
Yes. Content compressed with GZIP or DEFLATE will be properly decompressed. Be sure to add "Accept-Encoding: gzip" to the request header to notify the web server that you are accepting compressed content.
How do I handle JSON output from a Web API?
The addon skript-json was written specifically for this purpose. It converts JSON structures into plain Skript list variables for easy consumption. As an added bonus, skript-json will convert list variables into JSON if you need to send JSON to a Web API.