JSPM

geography-apis-sdk

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 2
    • Score
      100M100P100Q15592F
    • License ISC

    SDK for making requests to Geography APIs

    Package Exports

    • geography-apis-sdk
    • geography-apis-sdk/geography-apis-sdk.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (geography-apis-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Geography API Search SDK (JavaScript)

    License

    The CouGeography API Search SDK allows you to easily search for countries by name using a simple JavaScript interface. This SDK provides an abstraction over the API requests and handles common error scenarios to make it easier for developers to integrate country search functionality into their applications.

    Table of Contents

    Installation

    To use the SDK, you can install it via npm:

    npm install geography-apis-sdk

    Usage

    Initializing the SDK

    Before using the SDK, you need to initialize it with your API key and host:

    const CountrySearchSDK = require('geography-apis-sdk.bundle.js');
    
    const apiKey = 'YOUR_API_KEY';
    const apiHost = 'geography4.p.rapidapi.com';
    const baseURL = 'https://geography4.p.rapidapi.com';
    
    const countrySDK = new CountrySearchSDK(apiKey, apiHost, baseURL);

    Search for Countries by Name

    You can search for countries by their name using the searchByName method:

    const searchName = 'United States';
    const options = {
        headers: {
            'Content-Type': 'application/json'
        },
        params: {
            exactMatch: false,
            includeNativeName: false,
            fields: 'name,capital,population',
            sortBy: 'name',
            sortOrder: 'asc',
            limit: 10,
            offset: 0
        },
    };
    const countries = await countrySDK.searchCountriesByName(searchName, options);
    countries.then(countries => {
        // 'countries' is an array of Country objects
        console.log(countries);
      })
      .catch(error => {
        console.error('Error:', error.message);
      });

    Country Object

    The SDK returns an array of Country objects that represent the searched countries. Each Country object has the following properties:

    • name (object): Contains the name of the country, including the common name, official name, and native name.
    • capital (string): The capital city of the country.
    • population (number): The population of the country.
    • tld (string): The top-level domain of the country.
    • cca2 (string): The two-letter ISO code of the country.
    • cca3 (string): The three-letter ISO code of the country.
    • languages (object): Contains the official languages spoken in the country.
    • area (number): The total area of the country in square kilometers.
    • borders (array): An array of ISO codes of neighboring countries.
    • And many more properties with various information about the country.

    Error Handling

    The SDK handles different error scenarios to provide meaningful feedback to developers:

    • Invalid API key or host: The SDK ensures that you provide valid API credentials before making any requests.
    • API request errors: If there is an issue with the API request, the SDK throws an error with relevant information.
    • Empty response (status code 204): If the API response contains no content, the SDK returns a "No countries found" message.
    • Partial content response (status code 206): If the API response contains partial content, the SDK handles it gracefully.

    License

    This SDK is released under the MIT License. See the LICENSE file for more details.

    Contribution

    Contributions to this SDK are welcome! If you find any issues or want to add new features, please feel free to create a pull request or submit an issue.

    Support

    For any questions or support related to this SDK, please contact support@mmplabs.com.