Skip to content
Back

How to add queries to HTTPRequest

  • 0
  • Databases
  • REST API
xmaniaxz
22 Jan, 2025, 15:40

Hi,

I am working on a Minecraft mod that will gather data from an appwrite database. I got it working but i want to add Queries if possible.

This is my current code:

TypeScript
private void fetchPlayerRank(String playerName) {
        String url = APPWRITE_ENDPOINT + "/databases/" + DATABASE_ID + "/collections/" + COLLECTION_ID + "/documents";
        LOGGER.info("Fetching rank data for " + playerName + " from " + url);

        try {
            // Create the URL object
            URL urlObj = new URL(url);
            HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();

            // Set the request method and headers
            connection.setRequestMethod("GET");
            connection.setRequestProperty("X-Appwrite-Project", PROJECT_ID);
            connection.setRequestProperty("X-Appwrite-Key", API_KEY); 

            // Get the response code
            int statusCode = connection.getResponseCode();

            if (statusCode >= 200 && statusCode < 300) {
                // Success - process the response
                try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                    String inputLine;
                    StringBuilder response = new StringBuilder();

                    while ((inputLine = in.readLine()) != null) {
                        response.append(inputLine);
                    }

                    LOGGER.info("Rank data for " + playerName + ": " + response.toString());
                }
            } else {
                // Log unexpected status codes
                LOGGER.error("Unexpected response code: " + statusCode);
            }
        } catch (IOException e) {
            LOGGER.error("Failed to fetch rank data: ", e);
        }}
TL;DR
Developers wants to add queries to their HTTPRequest code for a Minecraft mod interacting with an appwrite database. They included their current code for fetching player rank data.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more