• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • Synchronization
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security, Resource Management, and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Network Namespace
        • Network Action Invoker Namespace
        • Network.fetch Action
        • Network.fetchBody Action
        • Network.fetchBytes Action
        • Network.fetchFile Action
        • Network.fetchJson Action
        • Network.fetchText Action
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • Sync Namespace
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Network.fetchBody Action

s = CS.Network.fetchBody(fetchId := ...
                     
ʃ, bodyFormat := ...ʅ
                     
ʃ, cancel := ...ʅ)
ArgumentDescriptionTypes / Required
fetchIdThe resource ID returned by Network.fetch.number
recommended
bodyFormatThe format in which the body is returned.
The default value is "dataUrl".
string
not required
cancelA flag indicating that the body can be discarded.boolean
not required
Description
The Network.fetchBody action processes the response of a HTTP request initiated by Network.fetch. The pending response is identified using fetchId, a resource ID returned by Network.fetch. While optional, this should generally be specified explicitly. (If there is only one pending response, the resource ID can be calculated implicitly.) Once the response is processed, the resource ID is no longer valid.
The argument cancel, if set to true, results in the body of the response being discarded. If you want to conditionally process a response, for example based on the value of a header, this is more efficient than retrieving the entire response using an action such as Network.fetchJson.
If retrieving the response, the argument bodyFormat determines how the body is returned. Options include:
  • "json": The response body is parsed as JSON, returning a string, number, boolean, array, or object. This is similar to Network.fetchJson.
  • "text": The response is returned as text. This is similar to Network.fetchText.
  • If bodyFormat is specified and not one of the above options, it is used to specify the format of the returned binary data. If requesting a large amount of data, consider using the "cache" format to avoid representing a huge number of bytes as a string. This is similar to Network.fetchBytes.
  • If no bodyFormat is specified, but the MIME type of the response is JSON or text-based, then it will be returned as JSON or text.
  • If none of the above rules apply, the response defaults to a data URL.
Return Value
The action returns the response body in the format specified. When discarding the body using cancel, the action returns undefined.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form, or if:
  • The fetch ID is not valid.
  • The connection times out.
  • The response is not valid for its type (e.g., invalid JSON).
Example (JavaScript)
// query information about the latest CSPro commit;
// the GitHub API requires the specification of a User-Agent header
const response = CS.Network.fetch({
    url: 
"https://api.github.com/repos/csprousers/cspro/commits?per_page=1",
    headers: [
       
"User-Agent: CSPro Help Documentation Example"
    ]
});

if (response.ok) {
   
// with a successful response, retrieve the body as JSON using the
    // resource ID (fetchId) returned from the initial call to Network.fetch
    const commits = CS.Network.fetchBody({
        fetchId: response.fetchId,
        bodyFormat: 
"json"
    });

   
const latestCommit = commits[0].commit;

    console.log(`Latest commit authored by 
"${latestCommit.author.name}", ` +
                `committed on 
"${latestCommit.committer.date}", ` +
                `
with message: "${latestCommit.message"}"`);
}
See also: Network Action Invoker Namespace, Network.fetch Action