I am making an API where users request to verify their Roblox accounts on Discord, and to complete the verification, they must join a game to complete it.
I already have the game down, just how would I make POST requests and get them from my API? I get the following error when I try to: HTTP 404 (Not Found)
Here is my API code so far:
const discord = require("discord.js")
const express = require("express")
const app = express()
const client = new discord.Client()
app.listen(3000, () => {
console.log("listening to port 3000.")
})
app.get("/:guildid", (req, res) => {
console.log("requested")
let guildId = req.params.guildid
if (!client.guilds.cache.get(guildId)) {
return res.json({"error": "unable to get guild"})
} else {
let guild = client.guilds.cache.get(guildId)
const Role = guild.roles.cache.find(role => role.name == "Nitro Booster");
const Members = guild.members.cache.filter(member => member.roles.cache.find(role => role == Role)).map(member => member.user.tag);
return res.json(Members)
}
})
My POST code:
local http = game:GetService("HttpService")
http:PostAsync("https://warmheartedsunnyflashdrive.unusualstudios.repl.co/805141926512558100", http:JSONEncode({name = "Script_Development"}))
It doesn’t “block” them, but if you change it to app.post instead of app.get your server will only accept POST requests sent, and then if you attempt to send GET requests it will say “404 not found”.
With this, if you send a GET request to [address]/test-get (for example http://localhost/test-get), you will be met with the “GET request to /test-get works!”, but if you tried to send a POST request to the same address, it wouldn’t work, because your app simply isn’t accepting that HTTP method on that route.
However, your app does accept POST requests to the [address]/test-post endpoint, and you would be met with the “POST request to /test-post works!” message. Again, if you were to send a GET request to this endpoint it would not work - and would respond with a 404 not found response.