npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geography-apis-sdk

v1.0.0

Published

SDK for making requests to Geography APIs

Downloads

9

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 [email protected].