Share your repls and programming experiences

← Back to all posts
ReplFiles! ~ Fetch ANY File from a Public Repl
h
RayhanADev (2513)

Hiya! It's Ray. Here's

ReplFiles!

Fetch ANY File from a Public Repl

Check out the API here
Quick Preview/Proof-of-Concept here

Storytime!

This is perhaps one of the more useful API's I've made for the Replit Community. I myself have always wanted to get files on a Repl, but (to my knowledge) there is no API endpoint or query to get files...

That's when @stungeye asked on the Feedback board for a tool to archive all Repls a Replit user has made. I set out to make such a tool and ended up with ArchiveIt. It fetches a .zip file available for every Repl at /@username/slug.zip, unzips the file to a folder, and then zips up the full folder of Repls.

It then dawned on me that I had access to EVERY file from those Repls. The NodeJS package Adm-Zip also makes accessing the content of all these files dirt simple. This trail led me to make this simple API that allows you to access any file, on any public Repl!

OKAY storytime over, here's how to use it :)

Usage

The API has two endpoints:

  • /file/{username}/{repl-slug}
  • and /files/{username}/{repl-slug}

The former is used for fetching a specific file. It returns an array with the file contents.
Example:
https://filesapi.replapiit.repl.co/file/RayhanADev/ArchiveIt?filename=src/index.js

You can also attach a raw=1 query to output the raw text without stringifying and nonsense.
Example:
https://filesapi.replapiit.repl.co/file/RayhanADev/ArchiveIt?filename=src/index.js&raw=1

--

The latter is used to get ALL files from a Repl. It returns an array with all files in a Repl. This uses a .gitignore file if present to filter out files.
Example:
https://filesapi.replapiit.repl.co/files/RayhanADev/ArchiveIt

and it's as simple as that! If you have any suggestions or ideas let me know in the comments below. Until next time :D.

P.S. ReplAPI.it integration with this API is on it's way >:)

Comments
hotnewtop
ANDREWVOSS (187)

These APIs just keep getting more interesting

DynamicSquid (4893)

Nice! That's something interesting I never thought of!

Coder100 (18071)

nice

but here's the question:
what if the user didn't rename the file and replit, as the bug still exists, doesn't get the file?

RayhanADev (2513)

@Coder100 :>? Please elaborate because I'm curious.

Coder100 (18071)

So basically, if you don't rename the file, replit doesn't actually include that file in the zip. This is only for things like user-uploaded files or programmatically created files @RayhanADev

RayhanADev (2513)

@Coder100 I did not know that :>
oh wait, I think I remember the old post on the old canny bug board

Yeah I can't really help with that since this is the only option that I know of :C. Do you have any ideas?

Coder100 (18071)

Well
Crosis ded
Erm
Well this is actually a really good way of doing it, just with that caveat xd @RayhanADev

RayhanADev (2513)

@Coder100 oof, I always wanted to use Crosis, never got the chance.
thx :3, I'll stick with this for now and think of any other ideas

ch1ck3n (2035)

pog

but you realize you can use this too right??

https://replbox.repl.it/data/web_hosting_1/tcsirvine_pgur/<repl slug>/<file name>

RayhanADev (2513)

@ch1ck3n what? How do I even use that lol

ALSO HOW DO YOU KNOW ABOUT REPLBOX???

RayhanADev (2513)

@ch1ck3n after messing around it seems that replbox is just a sandbox to run web repls???

RayhanADev (2513)

@ch1ck3n lmfao https://replbox.repl.it/data/web_hosting_1/RayhanADev/ReplFiles/files/RayhanADev/ArchiveIt?filename=src/index.js&raw=1

ch1ck3n (2035)

@RayhanADev

ALSO HOW DO YOU KNOW ABOUT REPLBOX???

a potato knows

(https://cknlinks.ch1ck3n.repl.co/dashboard/ feedback on the css pls)

RayhanADev (2513)

@ch1ck3n very, very nice!
Also I do believe chrome://dino is a valid url >:)

RayhanADev (2513)

Hey @ch1ck3n, you seem to be very versed in poking around Replit (actually the entire Blog class exists solely because of you LOL!) and you're really good at using Node/Web. Are you interested in joining the ReplAPI.it Project? I'm looking to get more people in on the project and I wanted to ask you first.

ch1ck3n (2035)

@RayhanADev and what exactly does that do and what do I have to do with it

RayhanADev (2513)

@ch1ck3n lol it just reads the blog rss feed, the existence of which I only know because of you (cough the post I made like a week or two ago)

RayhanADev (2513)

@ch1ck3n so what do you say, interested?

Enter y or n to continue...

RoBlockHead (520)

and what's the point of this as opposed to manually getting the file?

RayhanADev (2513)

@RoBlockHead are you asking for a use case?
Well say I wanted to get a file on someone else's Repl from my NodeJS application (maybe like a gallery of different user's projects and it shows project info and project code). Instead of finding the Repl and copy-pasting the code or using webscraping (yuck) there's an actual API to get the contents of a file, and it's easy to use :D!

I hope that makes sense...

RayhanADev (2513)

@RoBlockHead it's kinda similar to the usage of raw.githubusercontent.com. You can get the content of a file in a github repo through fetching the url.