How would I connect glitch with a game

Hi.
I’m wondering how would I connect Glitch with my game. For example, if you send something in-game and it would run an event in a glitch script (python) or the opposite.
Is this possible? Maybe with APIs?

Thank you!

Maybe! Or through sockets.

Run something here and be able to access on the other side

Can you tell me more about these, please?
In another game, there’s lua used

Does it happen to be Roblox? They have all kinds of APIs!
https://api.roblox.com/docs

Yes, but from Roblox to Python (A glitch project) and from Python to Roblox directly in the game.

Imagine, if I send some text to a glitch project and it would save as a json file and then tried to get that text in a game again.

Making an api with glitch is actually really simple.
You could add a GET or PUT route into your main file and execute some code on the server side.
I can provide code samples and such if you need it.

As @Realm_Melody said, you could have a basic API - using GET & POST requests.

For example if my project is called api1 and it has a GET method called hello and a POST method called world then I could use the following Roblox Lua code to make requests to the API endpoints.

local http = game:GetService("HttpService")

-- Make GET request

function doGet()
    local response
    if = pcall(function()
        response = http:GetAsync("https://api1.glitch.me/hello")
    end) then
        print("GET request worked!")
        print("Response: " .. response)
    end
end

-- Make POST request

function doPost(data)
    local postData = http:JSONEncode(data)
    local response
    if pcall(function()
        response = http:PostAsync("https://api1.glitch.me/world", postData)
    end) then
        print("POST request worked")
        print("Response: " .. response)
    end
end

-- Start
doGet()
doPost({
    hello = "world";
})

Okay. Thank you so much for that code!
How would I do it on glitch’s side?

Some very crude code just to give you an idea

const express = require("express");
const app = express();

app.get("/hello", (request, response) => {
//some code to get data from a json file
response.send(data);
//you could use response.json() for sending json data
});

app.post("/world", (request, response) => {
//Not familiar with Lua, not really sure how the data is posted to the server(ask xXProGamerXx about it)
//some code to save data to a json file
//you could response.send() something back to confirm success
});

Oh, is that possible with Python?

ah, not familiar with python, sorry.

Or maybe, how would I search on google for that?
Also, is there a way to protect anyone from accessing it?

:sweat_smile: Awhile back I was trying to make a simple multiplayer game. Where if a player moved you’d be able to see it on your client too.

The client was made in Java and the server was written with node.js. Basically the client would constantly send http requests for coordinates to the server. I had the server deployed on Glitch but after awhile I started get back 429 errors because it was just sending to many requests.


I think you should use something like https://socket.io/ rather then spamming your server lol.
The Coding Train YT channel has some good tutorials on using it!

I’m wondering if someone knows, what’s the code in python and how to protect it :confused:

What do you mean by how to protect it? Do you want nobody to see it?

The coding train also talks about glitch!

I suppose you want to make your code messed up and encrypted to stop copycats. There is a code tutorial here:

Make sure you have pip3.

Oh, I meant how to make a python api endpoint, but only working for me, not for anyone