Skip to content

A very simple method for running code from an external url in Google Script

Notifications You must be signed in to change notification settings

WillDev12/gs-httpget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

httpget for GS

Httpget is a useful function that allows you to evaluate code from a url. Using Google's UrlFetchApp api, you can create a similar function for Google user scripts.

Documentation

Warning: To perform an httpget, you must use an eval statement to run ALL code from the remote url. Because of this, it can be very easy to accidentally run malicious code if used recklessly. Please be careful when using this method.

As stated before, httpget simply fetches and evaluates any code placed in a remote url. This can be used for many reasons, such as minimizing installation steps (a quick copy and paste sure does the trick doesn't it?), fetching others' code without having to add a library (use the raw link), or in some cases shrinking file size.

Performing an httpget is simple. Using Google's Url Fetch Service, grabbing the code comes down to a one liner:

let data = UrlFetchApp.fetch("https://example.com/file.gs").getContentText();

Next, evaluate the code that the variable data returns:

eval(data);

Like I said before, please be careful when using this statement as it is INCREDIBLY easy to accidentally run malicious code. Since there is no other way to run code like this in gs, eval is the only alternative.

Full function

// Normal (100 bytes)
function httpget(url) {
    let data = UrlFetchApp.fetch(url).getContentText();
    eval(data);
}

// when using in function form, replace the
// actual url with an assignable variable.

// Compressed (59 bytes)
function l(s){eval(UrlFetchApp.fetch(s).getContentText());}

Library (If interested)

1U5RzdkF4G3QdK9HKJ3B6ScNewj7KThz17yjAyXT3AM-neyNTJQ9qa7Qf

Like content like this?

Follow my Github or share (this means a lot to me)

https://github.com/WillDev12
https://WillDev12.github.io

About

A very simple method for running code from an external url in Google Script

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published