Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willdev12/gs-httpget
A very simple method for running code from an external url in Google Script
https://github.com/willdev12/gs-httpget
google google-cloud google-script gs http httpget library urlfetchapp
Last synced: about 1 month ago
JSON representation
A very simple method for running code from an external url in Google Script
- Host: GitHub
- URL: https://github.com/willdev12/gs-httpget
- Owner: WillDev12
- Created: 2023-08-02T22:33:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-02T23:22:34.000Z (over 1 year ago)
- Last Synced: 2024-01-28T21:36:34.019Z (12 months ago)
- Topics: google, google-cloud, google-script, gs, http, httpget, library, urlfetchapp
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://developers.google.com/apps-script/reference/url-fetch), grabbing the code comes down to a one liner:
``` javascript
let data = UrlFetchApp.fetch("https://example.com/file.gs").getContentText();
```
**Next**, evaluate the code that the variable `data` returns:``` javascript
eval(data);
```
Like I said before, please be careful when using this statement as it is [INCREDIBLY](https://stackoverflow.com/a/13167699/20472970) 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
``` javascript
// 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](https://github.com/WillDev12) or share (this means a lot to me)
```
https://github.com/WillDev12
https://WillDev12.github.io
```