ballerinax/nytimes.articlesearch Ballerina library

1.5.1

Overview

This is a generated connector for New York Times Article Search API v1.0.0 OpenAPI specification. With the Article Search API, you can search New York Times articles from Sept. 18, 1851 to today, retrieving headlines, abstracts, lead paragraphs, links to associated multimedia and other article metadata. Use the Article Search API to look up articles by keyword. You can refine your search using filters and facets.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quickstart

To use the New York Times Article Search connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

First, import the ballerinax/nytimes.articlesearch module into the Ballerina project.

Copy
import ballerinax/nytimes.articlesearch as na;

Step 2: Create a new connector instance

Create a articlesearch:ApiKeysConfig with the API key obtained, and initialize the connector with it.

Copy
na:ApiKeysConfig config = {
    apiKey: "<API_KEY>"
}
na:Client baseClient = check new Client();

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.

    Following is an example on how to look up articles by keyword using the connector. You can now search for NYT articles by keywords, filters and facets. Here we have searched for articles with the word "election".

    Look up articles by keyword

    Copy
    public function main() {
        na:InlineResponse200|error response = baseClient->articleSearch("election");
        if (response is na:InlineResponse200) {
            na:InlineResponse200Response? inlineResponse200Response = response?.response;
            na:Doc[]? docs = inlineResponse200Response?.docs;
            if !(docs is ()) {
                foreach var doc in docs {
                    log:printInfo(doc?.'abstract.toString() + "\n");
                }
            }
        } else {
            log:printError(response.toString());
        }
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/nytimes.articlesearch;Copy

Metadata

Released date: over 1 year ago

Version: 1.5.1

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 1

Current verison: 1


Weekly downloads


Source repository


Keywords

Lifestyle & Entertainment/News & Lifestyle

Cost/Free


Contributors

Other versions

See more...