Skip to content

Configurations

Dickson Law edited this page Apr 4, 2021 · 5 revisions

Configurations

This library can be configured to your project's needs in the __REQM_CONFIGS__ script. The defaults that ship with the asset package should be suitable for most JSON-based APIs.

Available options are:

  • REQM_DEFAULT_SUBJECT The default subject to bind callbacks to. Valid values include:
    • xhr_subject_noone: Run callbacks anonymously.
    • xhr_subject_self: (Default) Run callbacks as the instance that started the request.
    • Any instance ID.
    • Any expression containing an instance ID.
  • REQM_DEFAULT_DECODER: Set the default response text decoder here. Valid values include:
    • string: Don't decode the response at all, treat it as-is.
    • json_parse: (Default) Decode JSON to plain structs via GML's built-in function.
    • jsons_decode: Decode JSON response to structs using the JSON Struct extension.
    • jsons_decode_safe: Decode JSON response to JsonStruct (safe mode) using the JSON Struct extension.
    • json_decode_to_map: Decode JSON response to maps using GML's built-in JSON decoder.
    • The name of any function that takes a string and returns a decoded result.
  • REQM_DEFAULT_ENCODER: Set the default request body encoder here. When an untyped struct is passed as the request body (i.e. those created using the {...} syntax, instead of new), it will be passed into a constructor to create a body helper, which sets required headers and helps mediate the request.
    • XwfuBody: (Default) Encode as a URL-encoded body (application/x-www-form-urlencoded). Unless otherwise specified, this is usually the format accepted by APIs.
    • MultipartBody: Encode as a multipart body (multipart/form-data). This is the format generally required for uploading file attachments.
    • StructBody: Encode as a JSON body (application/json) via GML's built-in json_stringify function.
    • JsonBody: Encode as a JSON body (application/json) via the JSON Struct extension.
    • The name of any constructor that takes an untyped struct and builds a typed struct implementing body helper methods (i.e. setHeader(map), getBody(), cleanBody(body) --- see the RequestBody script for examples)
  • xhr_url_root(<urlRoot>): Set the default URL root here (including the final slash). This will be automatically prepended to all relative request URLs (i.e. does not start with http: or https:). If you wish, you can also use this function in-game to change the URL root on the fly, or call it with no parameters to get the current URL root.

Clone this wiki locally