### HTTP GET Request Examples for remoteStorage Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/source.html Illustrates various HTTP GET request scenarios and their corresponding server responses within the remoteStorage protocol. This includes successful retrieval of JSON data, folder descriptions, and handling of 404 Not Found errors. ```http HTTP/1.1 200 OK Access-Control-Allow-Origin: [https://drinks-unhosted.5apps.com](https://drinks-unhosted.5apps.com) Content-Type: application/json; charset=UTF-8 Content-Length: 106 ETag: "1382694048000" Expires: 0 {"name":"test", "updated":true, "@context":"http://remotestora\nstorage.io/spec/modules/myfavoritedrinks/drink"} ``` ```http HTTP/1.1 200 OK Access-Control-Allow-Origin: [https://drinks-unhosted.5apps.com](https://drinks-unhosted.5apps.com) Content-Type: application/ld+json Content-Length: 171 ETag: "1382694048000" Expires: 0 {"@context":"[http://remotestorage.io/spec/folder-version](http://remotestorage.io/spec/folder-version)","items":{"test":{"ETag":"1382694048000","Content-Type":"application/json; \ncharset=UTF-8","Content-Length":106}}} ``` ```http HTTP/1.1 404 Not Found Access-Control-Allow-Origin: [https://drinks-unhosted.5apps.com](https://drinks-unhosted.5apps.com) ``` -------------------------------- ### JavaScript Ad Display and Setup Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/bbc-1/source.html Handles the setup and display of advertisements using Google Publisher Tag (GPT) and custom BBC ad functionalities. It involves creating DOM iframes for ad containers and setting base content for ad objects. ```javascript googletag.impl.pubads.createDomIframe("leaderboard_ad_container" ,"/4817/bbccom.live.site.mobile.news/news_usandcanada_content_0",false,false); ``` ```javascript bbcdotcom.ad("leaderboard").setBaseContent();googletag.display("leaderboard"); ``` ```javascript bbcdotcom.ad("sponsor_section").setBaseContent();googletag.display("sponsor_section"); ``` ```javascript bbcdotcom.ad("mpu").setBaseContent();googletag.display("mpu"); ``` -------------------------------- ### Oboe Audio Stream Setup Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/android-developers-blog/expected.html This C++ snippet demonstrates the basic setup for creating an Oboe audio stream. It configures performance mode, sharing mode, sets a data callback, and specifies the audio format. This is the initial step before populating audio data. ```c++ oboe::AudioStreamBuilder builder; builder.setPerformanceMode(oboe::PerformanceMode::LowLatency) ->setSharingMode(oboe::SharingMode::Exclusive) ->setDataCallback(myCallback) ->setFormat(oboe::AudioFormat::Float); ``` -------------------------------- ### Dependency Setup Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/android-developers-blog/source.html Add the necessary dependencies to your app's build.gradle file to use the Jetpack Tiles library. ```APIDOC dependencies { implementation "androidx.wear:wear-tiles:1.0.0-alpha01" debugImplementation "androidx.wear:wear-tiles-renderer:1.0.0-alpha01" } ``` -------------------------------- ### Fetch API - Basic Fetching Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/002/source.html Demonstrates how to perform a simple GET request using the fetch() function and handle the response. ```APIDOC ## GET /data.json ### Description Fetches data from a JSON endpoint. ### Method GET ### Endpoint /data.json ### Parameters None ### Request Example None ### Response #### Success Response (200) - **data** (object) - The JSON data returned from the endpoint. #### Response Example ```json { "entries": [ { "title": "Example Entry", "content": "This is an example." } ] } ``` ``` -------------------------------- ### iFrame Initialization and Setup Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/cnn/source.html The `setupIFrame` function is called to initialize and configure an individual iframe. It processes options, sets up scrolling behavior, defines size limits, and prepares the iframe for communication and resizing based on its ID and provided settings. ```javascript function setupIFrame(options) { var iframe = this, iframeId = ensureHasId(iframe.id); processOptions(options); setScrolling(); setLimits(); setupBodyMarginValues(); init(createOutgoingMsg()); } ``` -------------------------------- ### OAuth Dialog GET Request Example Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/expected.html Demonstrates an HTTP GET request to an OAuth endpoint for obtaining a bearer token. This request includes parameters for redirect URI, scope, client ID, and response type. ```HTTP GET /oauth/michiel?redirect_uri=https%3A%2F%2Fdrinks-unhosted.5apps.com%2F&scope=myfavoritedrinks%3Arw&client_id=https%3A%2F%2Fdrinks-unhosted.5apps.com&response_type=token HTTP/1.1 Host: 3pp.io ``` -------------------------------- ### Initial and Subsequent PUT Requests Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/source.html Illustrates how to perform initial resource creation using If-None-Match and subsequent updates using If-Match headers with ETags for concurrency control. ```HTTP PUT /storage/michiel/myfavoritedrinks/test HTTP/1.1 Authorization: Bearer j2YnGtXjzzzHNjkd1CJxoQubA1o= If-None-Match: * {"name":"test"} HTTP/1.1 201 Created ETag: "1382694045000" PUT /storage/michiel/myfavoritedrinks/test HTTP/1.1 Authorization: Bearer j2YnGtXjzzzHNjkd1CJxoQubA1o= If-Match: "1382694045000" {"name":"test", "updated":true} ``` -------------------------------- ### GET Resource Request Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/source.html Demonstrates a standard GET request for a resource, including the required Authorization bearer token. ```HTTP GET /storage/michiel/myfavoritedrinks/test HTTP/1.1 Host: 3pp.io:4439 Authorization: Bearer j2YnGtXjzzzHNjkd1CJxoQubA1o= ``` -------------------------------- ### Creating a Tile Preview Activity Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/android-developers-blog/expected.html Set up a debug activity to preview your Tile. This activity should be placed in `src/debug` and uses `TileManager` to render the Tile. ```APIDOC ## Creating a Tile Preview Activity ### Description Set up a debug activity to preview your Tile. This activity should be placed in `src/debug` and uses `TileManager` to render the Tile. ### Method `ComponentActivity` ### Endpoint N/A (Activity Implementation) ### Code Example ```kotlin import android.content.ComponentName import android.os.Bundle import android.widget.FrameLayout import androidx.activity.ComponentActivity import androidx.wear.tiles.TileManager class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val rootLayout = findViewById(R.id.tile_container) TileManager( context = this, component = ComponentName(this, MyTileService::class.java), parentView = rootLayout ).create() } } ``` ``` -------------------------------- ### JavaScript Timespan Class Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/sueddeutsche-1/source.html Defines a `Timespan` class to represent a period of time with a start, end, and duration. It includes a method to calculate the duration based on start and end times. ```javascript "use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){return t>=e?0:e-t}Object.defineProperty(e,"__esModule",{value:!0});var i=function t(e,n,i){r(this,t),this.name=e,this.start=n,this.end=i,this.duration=o(n,i)};e.default=i ``` -------------------------------- ### VigLink Initialization (JavaScript) Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/msn/source.html Initializes VigLink with a specific key and asynchronously loads the VigLink script. This is used for affiliate marketing or link monetization. ```javascript var vglnk = { key: '33701cec9fcd3b06ac687703f44f1f14' }; require(["c.deferred"], function() { require({ js: '//cdn.viglink.com/api/vglnk.js' }); }); ``` -------------------------------- ### OPTIONS Preflight Request Example Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/expected.html An example of an HTTP OPTIONS request made by a browser for a cross-origin request that may affect server state. It includes headers like Access-Control-Request-Method and Access-Control-Request-Headers. ```HTTP OPTIONS /storage/michiel/myfavoritedrinks/ HTTP/1.1 Host: 3pp.io:4439 Access-Control-Request-Method: GET Origin: https://drinks-unhosted.5apps.com Access-Control-Request-Headers: Authorization Referer: https://drinks-unhosted.5apps.com/ ``` -------------------------------- ### Initial PUT Request Example Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/expected.html Demonstrates an initial HTTP PUT request to store data, including headers like Content-Length, Origin, Authorization, and potentially 'If-None-Match: *' to ensure the resource does not already exist. ```HTTP PUT /storage/michiel/myfavoritedrinks/test HTTP/1.1 Host: 3pp.io:4439 Content-Length: 91 Origin: https://drinks-unhosted.5apps.com Authorization: Bearer j2YnGtXjzzzHNjkd1CJxoQubA1o= If-None-Match: * ``` -------------------------------- ### Perform GET Request for Resource Retrieval Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/expected.html Demonstrates a GET request to retrieve a resource or folder listing. It shows the use of the If-None-Match header for conditional requests and the expected JSON response format. ```http GET /storage/michiel/myfavoritedrinks/test HTTP/1.1 Host: 3pp.io:4439 Authorization: Bearer j2YnGtXjzzzHNjkd1CJxoQubA1o= If-None-Match: "1382694045000", "1382694048000" ``` -------------------------------- ### Real User Monitoring (RUM) Setup (JavaScript) Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/wapo-1/source.html Implements Real User Monitoring (RUM) by dynamically loading a performance monitoring script (wprum.min.js) via an iframe. This is done conditionally based on a random number to potentially reduce overhead. ```javascript !function(){if(!(Math.floor(100*Math.random())>99)){var a,b,c,d="//js.washingtonpost.com/wp-stat/rum/wprum.min.js",e=document.createElement("iframe");e.src="javascript:false",(e.frameElement||e).style.cssText="width: 0; height: 0; border: 0";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(e,c);try{b=e.contentWindow.document}catch(f){a=document.domain,e.src="javascript:var d=document.open();d.domain='"+a+"';void(0);",b=e.contentWindow.document}b.open()._l=function(){var b=this.createElement("script");a&&(this.domain=a),b.id="boomr-if-as",b.src=d,this.body.appendChild(b)},b.write('<body onload="document._l();">'),b.close()}}(); ``` -------------------------------- ### Initialize BBC Promo Manager Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/bbc-1/source.html This script initializes the promo manager module, which handles the asynchronous loading of footer promotional content based on user segments and cookie preferences. It uses the RequireJS pattern to load dependencies and track display events via istats. ```javascript (function() { 'use strict'; var promoManager = { /* ... implementation ... */ init: function(node) { /* ... logic ... */ } }; define('orb/promomanager', ['orb/lib/_event'], function (event) { event.mixin(promoManager); return promoManager; }); require(['orb/promomanager'], function (promoManager) { promoManager.init(document.getElementById('orb-footer-promo')); }) })(); ``` -------------------------------- ### DOM Element Hierarchy Traversal Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/faz-1/source.html This utility function traverses the DOM hierarchy starting from a given element, collecting all ancestor elements up to the document's head or body. It then concatenates these ancestors with all descendant elements of the starting element. ```javascript function r(e){for(var t=[],r=e;r&&!n.i(a.d)(r,"html","head","body");)t.push(r),r=r.parentElement;t.reverse();var o=e.querySelectorAll("*");return t.concat(i()(o))}var o=n(6),i=n.n(o),a=n(50);t.a=r ``` -------------------------------- ### GET /storage/{user}/{document} Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/source.html Retrieves a specific document or a folder description from remote storage. Supports conditional GET requests using If-None-Match and handles various response codes including 304 Not Modified, 200 OK, and 404 Not Found. ```APIDOC ## GET /storage/{user}/{document} ### Description Retrieves a specific document or a folder description from remote storage. Supports conditional GET requests using If-None-Match and handles various response codes including 304 Not Modified, 200 OK, and 404 Not Found. ### Method GET ### Endpoint /storage/{user}/{document} ### Query Parameters None ### Request Example (No request body for GET) ### Response #### Success Response (200 OK) - **Content-Type** (string) - The MIME type of the content. - **ETag** (string) - The ETag of the document or folder. - **Expires** (string) - Expiration date. - **body** (object/json) - The content of the document or folder description. #### Success Response (304 Not Modified) - **Access-Control-Allow-Origin** (string) - The allowed origin for CORS. - **ETag** (string) - The ETag of the document or folder. #### Error Response (404 Not Found) - **Access-Control-Allow-Origin** (string) - The allowed origin for CORS. #### Response Example (200 OK - Document) ```json { "name": "test", "updated": true, "@context": "http://remotestorage.io/spec/modules/myfavoritedrinks/drink" } ``` #### Response Example (200 OK - Folder) ```json { "@context": "http://remotestorage.io/spec/folder-version", "items": { "test": { "ETag": "1382694048000", "Content-Type": "application/json; charset=UTF-8", "Content-Length": 106 } } } ``` #### Response Example (304 Not Modified) ``` HTTP/1.1 304 Not Modified Access-Control-Allow-Origin: https://drinks-unhosted.5apps.com ETag: "1382694048000" ``` #### Response Example (404 Not Found) ``` HTTP/1.1 404 Not Found Access-Control-Allow-Origin: https://drinks-unhosted.5apps.com ``` ``` -------------------------------- ### Construct and Configure Request Objects Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/002/source.html Shows how to create basic Request objects, copy existing requests, and configure advanced options like HTTP methods, headers, and body content. ```javascript var req = new Request("/index.html"); var copy = new Request(req); var uploadReq = new Request("/uploadImage", { method: "POST", headers: { "Content-Type": "image/png" }, body: "image data" }); ``` -------------------------------- ### Creating and Copying Request Objects Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/002/expected.html Shows how to initialize a basic Request object from a URL and how to create a copy of an existing Request instance. ```javascript var req = new Request("/index.html"); console.log(req.method); // "GET" console.log(req.url); // "http://example.com/index.html" var copy = new Request(req); console.log(copy.method); // "GET" console.log(copy.url); // "http://example.com/index.html" ``` -------------------------------- ### Configuring Request with Custom Options Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/002/expected.html Demonstrates creating a Request with specific HTTP methods, custom headers, and a request body. ```javascript var uploadReq = new Request("/uploadImage", { method: "POST", headers: { "Content-Type": "image/png", }, body: "image data" }); ``` -------------------------------- ### Basic Fetch GET Request in JavaScript Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/002/expected.html Demonstrates how to perform a simple GET request using the fetch() function. It retrieves data from a JSON endpoint and processes the response, handling both successful and error cases. The function returns a Promise that resolves to a Response object. ```javascript fetch("/data.json").then(function(res) { // res instanceof Response == true. if (res.ok) { res.json().then(function(data) { console.log(data.entries); }); } else { console.log("Looks like the response wasn't perfect, got status", res.status); } }, function(e) { console.log("Fetch failed!", e); }); ``` -------------------------------- ### GET /storage/{path} Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/source.html Retrieves a resource from the remote storage. ```APIDOC ## GET /storage/{path} ### Description Fetches the content of a stored resource. ### Method GET ### Endpoint /storage/{path} ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token - **If-None-Match** (string) - Optional - ETag to check for freshness ``` -------------------------------- ### OPTIONS Preflight Response Example Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/expected.html A sample HTTP 200 OK response to an OPTIONS preflight request, indicating allowed origins, methods, and headers for cross-origin requests. ```HTTP HTTP/1.1 200 OK Access-Control-Allow-Origin: https://drinks-unhosted.5apps.com Access-Control-Allow-Methods: GET, PUT, DELETE Access-Control-Allow-Headers: Authorization, Content-Length, Content-Type, Origin, X-Requested-With, If-Match, If-None-Match ``` -------------------------------- ### Readability.js Configuration Example Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/faz-1/source.html This snippet demonstrates how to configure Readability.js with specific settings, such as account ID and content control callbacks. It also shows domain configurations for different environments. ```javascript window._sp_ = window._sp_ || {}; window._sp_.config = window._sp_.config || {}; window._sp_.config.account_id = 329; if (isCCC) { window._sp_.config.content_control_callback = function () { window.location.href = 'http://www.' + (isLive ? 'faz' : 'testfaz') + '.net/aktuell/so-deaktivieren-sie-ihren-adblocker-15078142.html'; }; } window._sp_.config.mms_domain = 'faz-de.'+(isLiv ``` -------------------------------- ### GET /document-or-folder Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/ietf-1/source.html Retrieves the content of a document or the listing of a folder. ```APIDOC ## GET /path/to/resource ### Description Retrieves a document's content or a folder's description. If a folder is empty, it returns an empty items object. ### Method GET ### Endpoint /{path} ### Response #### Success Response (200) - **Content-Type** (header) - The MIME type of the document. - **Content-Length** (header) - Size of the document in octets. - **ETag** (header) - Strong validator representing the document version. #### Response Example { "items": { "doc1": { "ETag": "v1" } } } ``` -------------------------------- ### Dynamic Script Loading and Personalization (JavaScript) Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/tmz-1/source.html This JavaScript code dynamically loads scripts for personalization and analytics. It constructs URLs based on site GUID, user GUID, and other parameters, then injects script tags into the document. It handles different protocols and checks for existing jQuery instances. ```javascript function(){ window.gravityInsightsParams = { 'type': 'content', 'action': '', 'site_guid': '82893b79564009a4d8fab7b9db32cfea' }; var adServerReq,bUrl,cburl,doUseGravityUserGuid,includeJs,jq,pfurl,type,ug,wlPrefix,wlUrl,_ref,_ref1,_ref2;includeJs=function(a){var b;b=document.createElement("script");b.async=!0;b.src=a;a=document.getElementsByTagName("script")[0];return a.parentNode.insertBefore(b,a)};bUrl="";ug=(doUseGravityUserGuid=!0===gravityInsightsParams.useGravityUserGuid?1:0)?"":gravityInsightsParams.user_guid||(null!=(\_ref=/grvinsights=([^;]+)/.exec(document.cookie))?\_ref[1]:void 0)||""; wlUrl=(wlPrefix="https:"===location.protocol?"https://secure-api.gravity.com/v1/api/intelligence":"http://rma-api.gravity.com/v1/api/intelligence",jq=(null!=(\_ref1=window.jQuery)?null!=(\_ref2=\_ref1.fn)?\_ref2.jquery:void 0:void 0)|| "",type="iframe",adServerReq=gravityInsightsParams.ad||"",cburl=gravityInsightsParams.cburl||"",pfurl=gravityInsightsParams.pfurl||"",""+wlPrefix+"/wl?jq="+jq+"&sg="+gravityInsightsParams.site_guid+"&ug="+ug+"&ugug="+doUseGravityUserGuid+"&id=grv-personalization-13&pl=13"+("&type="+type+"&ad="+adServerReq+"&cburl=")+encodeURIComponent(cburl)+"&pfurl="+encodeURIComponent(pfurl)+("&x="+(new Date).getTime())+ ("undefined"!==typeof forceArticleIds&&null!==forceArticleIds&&forceArticleIds.join?"&ai="+forceArticleIds.join(","):"")+("undefined"!==typeof apids&&null!==apids&&""!==apids?"&apids="+encodeURIComponent(apids):""));bUrl&&includeJs(bUrl);wlUrl&&(window.gravityInsightsParams.sidebar&&(window.gravityInsightsParams.wlStartTime=(new Date).getTime()),includeJs(wlUrl))}() ``` -------------------------------- ### GET /resource Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/002/expected.html Retrieves a resource from the network using the fetch function. ```APIDOC ## GET /resource ### Description Fetches a resource from the specified URL and returns a Promise that resolves to a Response object. ### Method GET ### Endpoint /resource ### Parameters #### Path Parameters - **url** (string) - Required - The URL of the resource to fetch. ### Request Example fetch("/data.json") ### Response #### Success Response (200) - **res** (Response) - The Response object containing the resource data. #### Response Example { "entries": [...] } ``` -------------------------------- ### Initialize Ad Configuration Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/test-pages/yahoo-1/source.html This snippet shows the configuration for ad-related features, including frequency, pagination, and blending. It also details UI-specific settings for ad display. ```javascript { "niAdFeedback": true, "frequency": 3 }, "batches": { "pagination": false, "size": 32, "start_index": 19, "end_index": 31 }, "blending_enabled": true, "extended_sidekick": true, "category": "SIDEKICK:TOPSTORIES", "i13n": { "sec": "sdkick" }, "max_exclude": 10, "ui": { "attribution_pos": "bottom", "featured_summary": false, "follow_content": false, "inline_filters_max": 0, "magazine_icon": false, "summary": false, "view": "sidekick", "title": "disabled" }, "video": { "use_inline_video": false }, "use_prefetch": true ``` -------------------------------- ### URL Generation and Configuration in JavaScript Source: https://github.com/dankito/readability4j/blob/master/src/test/resources/additional-test-pages/sueddeutsche-1/source.html This JavaScript code provides utility functions for generating various URLs related to user authentication and redirection. It includes methods for setting up the service URL, getting login, logout, and profile URLs, and checking the login state. The `setup` method is crucial for initializing the service URL. The `getLoginUrl` function constructs a login URL, optionally including a gateway parameter. `getLogoutUrl` creates a logout URL with a `logout=true` parameter appended to the current page's URL. `getProfileUrl` generates a URL for user profile actions. `getLoginState` fetches the user's login status via an XMLHttpRequest. ```javascript Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(t,e){for(var n=0;n 0) { for (var i = 0; i < firstRender.length; i++) { var position = firstRender[i]; var index = prefetchedPos.indexOf(position); if (index >= 0) { firstBatchPos = firstBatchPos.concat(prefetchedPos.splice(index, 1)); } }; } if (firstBatchPos.length > 0) { var re ```