SDKs overview

OnWater provides Software Development Kits (SDKs) and client libraries designed to simplify interaction with its API. These tools encapsulate the underlying HTTP requests and JSON parsing, allowing developers to focus on integrating the core functionality of determining if a given latitude and longitude coordinate is located on water or land. The primary API endpoint, documented in the OnWater API reference, accepts geographic coordinates and returns a boolean value along with details about the water body if applicable. SDKs are typically language-specific packages that handle authentication, request formatting, and response deserialization, streamlining development for various programming environments.

Integrating with the OnWater API via an SDK avoids the necessity of directly managing HTTP client implementations or error handling for common API responses. This approach can reduce development time and potential integration errors. For instance, an SDK might automatically retry requests or handle rate limiting if the API imposes such constraints, although the OnWater documentation does not explicitly detail these features for its client libraries. SDKs also often provide an object-oriented interface, mapping API concepts to natural programming constructs within the chosen language.

While official SDKs are maintained by OnWater, community-contributed libraries may also exist. These community efforts can offer alternative implementations, support for less common languages, or integration into larger frameworks. Developers should evaluate the maintenance status, documentation, and licensing of community libraries before incorporating them into production systems, as their reliability and support models can vary compared to official releases.

Official SDKs by language

OnWater offers official SDKs and client libraries that support several popular programming languages. These libraries are developed and maintained by OnWater to ensure compatibility with the latest API versions and to provide a consistent developer experience across different platforms. Each SDK is tailored to the conventions and idioms of its respective language, facilitating easier adoption and integration into existing projects. The following table provides an overview of the officially supported SDKs:

Language Package Name / Repository Install Command (Example) Maturity
Python onwater.py pip install onwater Stable
Node.js onwater-node npm install onwater-node Stable
PHP onwater/onwater-php composer require onwater/onwater-php Stable
Ruby onwater-ruby gem install onwater-ruby Stable
Go github.com/onwater/go-onwater go get github.com/onwater/go-onwater Stable

These SDKs are designed to abstract the direct HTTP calls to the OnWater REST API endpoint, streamline parameter passing, and handle the parsing of JSON responses into native language data structures. Developers are encouraged to consult the specific documentation for each SDK for detailed usage instructions and examples.

Installation

Installation of OnWater SDKs typically follows the standard package management practices for each programming language. The process generally involves using a command-line tool to fetch the library from a public repository and add it to your project's dependencies. An API key, obtained from your OnWater account dashboard, is required to authenticate requests made through the SDKs.

Python

For Python projects, the onwater library is available via pip, the Python package installer. Ensure you have pip installed, which typically comes with Python distributions. To install:

pip install onwater

After installation, you can import the library and use it in your Python scripts. Python's package management system is detailed in the official Python packaging documentation.

Node.js

Node.js developers can install the onwater-node package using npm (Node Package Manager). Navigate to your project directory and execute:

npm install onwater-node

This command adds the library to your node_modules directory and updates your package.json file. For further details on npm usage, refer to the npm install documentation.

PHP

PHP projects commonly use Composer for dependency management. To add the OnWater PHP library to your project, run the following command in your project's root directory:

composer require onwater/onwater-php

This command will download the library and update your composer.json and composer.lock files. Ensure Composer is installed and accessible via your command line.

Ruby

Ruby projects utilize RubyGems for package management. Install the onwater-ruby gem by running:

gem install onwater-ruby

Once installed, you can require the gem in your Ruby applications or Rails projects to access its functionalities.

Go

For Go applications, libraries are typically fetched using the go get command. To install the OnWater Go client:

go get github.com/onwater/go-onwater

This command downloads the package into your Go module cache. You can then import it into your Go source files.

Quickstart example

This section provides a basic quickstart example using the Python SDK to demonstrate how to check if a specific coordinate is on water. This example assumes you have already installed the Python SDK and have your OnWater API key available.

Python Quickstart

First, ensure your API key is configured. It's recommended to store API keys securely, for example, as environment variables, rather than hardcoding them directly into your source code. The OnWater documentation provides guidance on API key management and authentication.

import os
from onwater import onwater

# Replace with your actual OnWater API Key, or load from environment variable
API_KEY = os.environ.get("ONWATER_API_KEY", "YOUR_ONWATER_API_KEY")

# Initialize the OnWater client
client = onwater.OnWater(api_key=API_KEY)

# Define coordinates to check (e.g., San Francisco Bay)
latitude = 37.79
longitude = -122.39

try:
    # Make the API call
    response = client.check(latitude, longitude)

    # Process the response
    if response.is_water:
        print(f"Coordinate ({latitude}, {longitude}) is on water.")
        if response.water_body_name:
            print(f"Water body: {response.water_body_name}")
    else:
        print(f"Coordinate ({latitude}, {longitude}) is on land.")
    
    # Access full response data for debugging or more detailed information
    # print(response.raw_data)

except onwater.OnWaterError as e:
    print(f"An error occurred: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

This Python snippet initializes the OnWater client with an API key, then calls the check method with a latitude and longitude. It then prints whether the coordinate is on water and, if so, the name of the water body. Error handling is included to catch potential issues during the API call or response processing. This example demonstrates the core functionality of the OnWater API and its Python SDK.

Community libraries

Beyond the official SDKs, the developer community may contribute client libraries or integrations for languages and frameworks not officially supported by OnWater. These community-driven projects can offer flexible solutions, but their stability, maintenance, and feature parity with the official API might vary. As of the current date, specific widely recognized community libraries for OnWater beyond its official offerings are not prominently documented in the public domain. Developers seeking community-maintained alternatives are advised to search public code repositories like GitHub or relevant package managers for their target language. When evaluating community libraries, it is important to consider the following factors:

  • Active Maintenance: Is the library regularly updated to reflect changes in the OnWater API or language best practices?
  • Documentation: Does the library provide clear installation instructions and usage examples?
  • Licensing: Is the library distributed under an open-source license that aligns with your project's requirements?
  • Community Support: Is there an active community or maintainer responsive to issues and pull requests?
  • Security Audit: Has the library undergone any security reviews, especially if handling sensitive data or credentials?

While official SDKs are generally the recommended path for integration due to direct vendor support and guaranteed compatibility with the OnWater API, community contributions can sometimes offer specialized features or integrations with niche ecosystems. For example, a community library might provide an adapter for a specific geospatial framework that streamlines data processing before making calls to OnWater.

Developers are encouraged to review the official OnWater documentation for the most up-to-date information on supported integration methods and to ensure compliance with API usage policies, regardless of the chosen integration library.