Skip to main content

Making custom requests

What are custom requests?

Custom requests are requests made to the ER:LC API manually. There are a few ways to do it, but erlc.js has a built-in way of making custom requests.

Why would I need to do this?

Well, if erlc.js ever stops being updated (hopefully never!), but the ER:LC API is still being worked on, you'll need to make your own to the new endpoints.

Wait, what are endpoints?

Endpoints are what goes on the end of the API link. With erlc.js, you should only have to use them for custom requests.

OK, so how do I do it?

Well, there are 2 ways:

  • the manual way
  • the super manual way

Here's how to do the easier, normal manual one, which is what you'll mostly be using.

The manual way

Each Server has a .makeRequest() method.

Here's the syntax:

privateServer.makeRequest(
"API-ENDPOINT",
"REQUEST-METHOD",
VERSION-NUMBER,
{
DATA: "IF APPLICABLE"
})

API-ENDPOINT: The endpoint you're making the request to.

REQUEST-METHOD: The request type. Usually "GET" or "POST". Accepts all methods listed in the Mozilla Docs.

VERSION-NUMBER: The API version. Defaults to 1

DATA: A table of data to be sent with the request. Returns an error if used with "GET" or "HEAD" request methods.

It then returns the response from the API. You may have to run .json() on the response object to make it useful. Note that .json() takes a few seconds to run, so you'll have to use await or .then().

The super manual way

If you're using this way, you probably don't even need erlc.js, but still, here's the super manual way.

JS has a built-in function called fetch(), here's how you can use it.

fetch(
"FULL-API-URL",
{
method: "METHOD",
headers: {
"Server-Key": "SERVER-KEY",
"Authorization": "AUTHORIZATION-KEY-IF-APPLICABLE", // Remove this line if you don't have one
"Content-Type": "application/json" // Keep the same
},
body: JSON.stringify({
"DATA": "IF-APPLICABLE"
})
})

FULL-API-URL: The full API URL, not just the endpoint

METHOD: The request type. Usually "GET" or "POST". Accepts all methods listed in the Mozilla Docs.

AUTHORIZATION-KEY-IF-APPLICABLE: The authorization key if you have one.

application/json: Keep this the same

DATA-IF-APPLICABLE: The data to be sent with the request.

End of the Guide

This is the end of the guide! Next, go on to the full Documentaion.