Web Module
This modules contains every internal function related to the web (making web requests).
Documentation
Function documentation is using a specific syntax. More information here.
tp.web.daily_quote()
Retrieves and parses the daily quote from https://github.com/Zachatoo/quotes-database
as a callout.
Examples
// Daily quote
<% tp.web.daily_quote() %>
tp.web.random_picture(size?: string, query?: string, include_size?: boolean)
Gets a random image from https://unsplash.com/
.
Arguments
-
size
: Image size in the format<width>x<height>
. -
query
: Limits selection to photos matching a search term. Multiple search terms can be passed separated by a comma. -
include_size
: Optional argument to include the specified size in the image link markdown. Defaults to false.
Examples
// Random picture
<% tp.web.random_picture() %>
// Random picture with size
<% tp.web.random_picture("200x200") %>
// Random picture with size and query
<% tp.web.random_picture("200x200", "landscape,water") %>
tp.web.request(url: string, path?: string)
Makes a HTTP request to the specified URL. Optionally, you can specify a path to extract specific data from the response.
Arguments
-
url
: The URL to which the HTTP request will be made. -
path
: A path within the response JSON to extract specific data.
Examples
// Simple request
<% tp.web.request("https://jsonplaceholder.typicode.com/todos/1") %>
// Request with path
<% tp.web.request("https://jsonplaceholder.typicode.com/todos", "0.title") %>
Examples
// Daily quote
<% tp.web.daily_quote() %>
// Random picture
<% tp.web.random_picture() %>
// Random picture with size
<% tp.web.random_picture("200x200") %>
// Random picture with size and query
<% tp.web.random_picture("200x200", "landscape,water") %>
// Simple request
<% tp.web.request("https://jsonplaceholder.typicode.com/todos/1") %>
// Request with path
<% tp.web.request("https://jsonplaceholder.typicode.com/todos", "0.title") %>