Learn to Code via Tutorials on Repl.it!

← Back to all posts
Repl.it api example
h
Coder100 (3985)

Hi everyone, so I asked a question on AMA and here is where I am now.

Introduction

To learn graphQL, go here and maybe you want to search up graphQL tutorial as well on google if you are not familiar with the querying language (it's like JSON but less strict and better)


Ok, now you want to go to the headers tab, and type in this:

{
  "X-Requested-With": "coder100",
  "Referrer":"https://repl.it"
}

X-requested-with can be anything and referrer IDK about.
Now it's time to do some query-ing!

Query the heck out of there

Now, in the editor, let's get all the information about you

# Write your query or mutation here
{
  userByUsername(username: "[username]") {
    karma, id, firstName, lastName, bio, isVerified
  }
}

Interestingly, cycles are called karma like on reddit....repl.it coins? lol

Share

Now, make a bash file on repl.it and copy the CURL code (located in the top right) and paste it in the REPL and click run. Ugly compressed JSON code should be seen (if not an error), and this is where you have to do some things. Where you see the username: "[username]" part, escape it out so it looks like username: \"[username]\". Ok, now go to your favorite JSON beautifier and look at the fruit of your labor.

ENJOY!

A REPL of mine is put on this tutorial to show you how awesome graphQL is!

Homework

Try to do this in node.js it won't be hard as all the headers necessary are there!

Commentshotnewtop
Zexogon (905)

This is one of the scenarios where python is just easier

Also cool 1 line post

Coder100 (3985)

Thanks! Hope it won't get flagged because bash commands can only be one line :P I think some of those headers aren't necessary but this is still pretty good. Node.js will be good for this i think since it is synchronous by default. @Zexogon

Warhawk947 (520)

@Zexogon yea mat1's repltalk is much more easier to use

MrEconomical (2198)

@Zexogon more like this is one of the scenarios where node.js is just easier

Coder100 (3985)

lol yeah
axios is superior to requests >:) @MrEconomical

abc3354 (214)

Note : I am actually translating mat's api in node.js, it is another way to use the api with graphql under the hood

Coder100 (3985)

publish it on NPM! However I wouldn't recommend using mat's api when you can just use node-fetch for all of the get things @abc3354

abc3354 (214)

@Coder100
I will !
And I am not sure I want to learn graphql lol (maybe a day)

AdCharity (1270)

how do you fetch it with javascript? I assume you use ajax or simply fetch?

Coder100 (3985)

yeah, node-fetch with the appropriate headers. example @AdCharity

Coder100 (3985)

Try not to use my sensitive info but ok @AdCharity