You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Node.js环境中调用Europe PMC SOAP Web服务?求JavaScript示例

Hey folks! If you're looking to interact with the Europe PMC SOAP Web Service using Node.js, I've got you covered. Let's go through the process step by step, including a fully functional example to get you up and running quickly.

Calling Europe PMC SOAP Web Service with Node.js

1. First, Install the Required Dependency

Node.js doesn't have built-in SOAP support, so we'll use the popular soap npm package to handle the heavy lifting. Install it via npm:

npm install soap

2. Know the Europe PMC SOAP WSDL

Europe PMC provides a public WSDL for its SOAP services, which acts as the "blueprint" for the service methods and data structures. The main WSDL URL is:
https://www.ebi.ac.uk/europepmc/webservices/soap?wsdl

We'll use this URL to generate a SOAP client in our code.

3. Core Steps to Make the Call

Here's the high-level workflow for interacting with the service:

  • Import the soap library
  • Generate a SOAP client by loading the WSDL
  • Call the specific service method with your desired parameters
  • Handle the response (or any errors that pop up)

4. Full Working Example

Let's put this into action with an example that uses the searchPMC method to fetch papers related to the keyword "CRISPR". This method returns a list of matching publications along with metadata:

const soap = require('soap');

// WSDL URL for Europe PMC SOAP service
const europePMCWsdl = 'https://www.ebi.ac.uk/europepmc/webservices/soap?wsdl';

// Async function to handle the SOAP call
async function fetchEuropePMCPapers() {
  try {
    // Create the SOAP client (async version for cleaner code)
    const client = await soap.createClientAsync(europePMCWsdl);

    // Define your request parameters
    // Check Europe PMC's docs for all available params per method
    const requestOptions = {
      query: 'CRISPR',
      pageSize: 5, // Return 5 results
      page: 1,     // Fetch the first page
      sort: 'CITED' // Sort by citation count (optional)
    };

    // Call the searchPMC method (async variant)
    const [response] = await client.searchPMCAsync(requestOptions);

    // Process the results
    console.log(`Total papers found: ${response.hitCount}`);
    console.log('\nFirst 3 papers:');
    response.resultList.result.slice(0, 3).forEach((paper, index) => {
      console.log(`\n${index + 1}. ${paper.title}`);
      console.log(`   Authors: ${paper.authorString}`);
      console.log(`   Journal: ${paper.journalTitle}`);
    });

  } catch (err) {
    console.error('Error calling Europe PMC SOAP service:', err);
  }
}

// Run the function
fetchEuropePMCPapers();

5. Key Notes to Keep in Mind

  • Async/Await: We're using the async variants of the soap methods (like createClientAsync and searchPMCAsync) to avoid callback hell and make the code more readable.
  • Parameter Validation: Make sure to pass the correct parameters for each method. You can refer to Europe PMC's SOAP service documentation to see all available methods and their required/optional parameters.
  • Client Configuration: If you need to adjust timeouts, add headers, or tweak other settings, you can pass a configuration object when creating the client:
    const client = await soap.createClientAsync(europePMCWsdl, {
      timeout: 15000, // 15-second timeout
      // Add other configs like proxy, headers, etc. here
    });
    

内容的提问来源于stack exchange,提问作者Yuci

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:40:57