Ask coding questions

← Back to all posts
Replit DataBase/API
StevesGreatness (0)

What I mean by a Replit DB is if Replit has made something like the "Rest API."

Comments
hotnewtop
RayhanADev (2611)

Hiya @StevesGreatness

Replit has a few dozen APIs, if you're asking about ReplDB's API I'd take a look at the source code (https://github.com/cursorweb/repl.it-db) to see the endpoints.

If you want to know about the other APIs there is a Restful API but that is typically used for Replit meta and Container connections. The GraphQL API is useful for projects integrating Replit, take a look at ReplAPI.it an API package I made (keep in mind its under a revision and currently broken: https://github.com/ReplAPI-it/ReplAPI.it-NodeJS/tree/c9f37b4f5f24fc51af4f4859db9f3808da10ef7f/esm/src/classes) that should give you some information about the different queries :).

If you have any specific questions or use cases I can try to answer them for you!

StevesGreatness (0)

@RayhanADev does the nodejs api also support vanilla js(in conjunction with html and css)?
note: I have no idea how nodejs works...

Coder100 (18911)

no node.js is the backend version, the stuff that powers the HTML @StevesGreatness

RayhanADev (2611)

@StevesGreatness nah and I can't assure you that it'd work rn anyways, but if you need a basic implementation:

async function getMyCycles() {
  const data = await fetch('https://replit.com/graphql', {
    method: 'POST',
    headers: {
      'X-Requested-With': 'RayhanADev',
      'Referrer': 'https://replit.com/'
    },
    body: JSON.stringify({
        query:
`query UserCycles($username: String!) {
  userByUsername(username: $username) {
    karma
  }
}`,
      variables: JSON.stringify({
        username: 'RayhanADev'
      })
    })
  });

  if(res.status !== 200) throw new Error('Something went wrong!');
  return await res.json();
}