Smartfetch icon

Smartfetch

HTTP GET request with built-in caching

Smartfetch

AI-generated

Summary

Performs HTTP GET requests with caching to reduce redundant network calls and improve performance.

Inputs

  • url (required) — The URL to fetch.
  • authentication — The authentication method to use (Basic, Bearer, Digest, Header, Query, or None).
  • cacheStorage — Where to store cached responses (Memory or PostgreSQL).
  • cacheTableName — PostgreSQL table name for cache (required when cacheStorage is PostgreSQL).
  • cacheDuration — How long to cache responses (5 Minutes to 1 Month or Custom).
  • customTtl — Custom cache duration in seconds (visible when cacheDuration is Custom).

Output shape

A list of items, one per input item. If cached, returns the cached JSON data; if not, performs a GET request and caches the response before returning it.

Errors return an item with an error envelope containing the error message and the URL. For PostgreSQL caching, the table is created automatically if it does not exist. Memory cache is limited to 1000 entries.

Examples

Example 1: Cache a frequently requested API endpoint for 1 hour using memory storage.

Set URL to the API endpoint, Authentication to 'None', Cache Storage to 'Memory', and Cache Duration to '1 Hour'.

Example 2: Persist API responses across n8n restarts using PostgreSQL with a custom 30-minute TTL.

Set Cache Storage to 'PostgreSQL', enter a valid table name, set Cache Duration to 'Custom', and specify 1800 seconds for customTtl.

Example 3: Fetch data from an authenticated endpoint and store it in PostgreSQL for long-term caching.

Select the appropriate authentication method (e.g., 'Basic Auth') and Cache Storage as 'PostgreSQL' with a 1 Day cache duration.

Links

Discussion