Deploying APIs with Daisies

Eric Hare
Daisi Technology
Published in
5 min readAug 4, 2022

In three easy steps

TL;DR

We’ve developed a new Daisi called NOAA Weather. We’re highlighting it because, despite it’s relative simplicity, it shows you both the ease and the power that the Daisi Platform provides to developers who wish to have 24/7 access to their endpoints, so that users can interact with it, and applications can be built which seamlessly integrate the functionality.

Background

The Daisi Serverless Platform allows scientific computing tasks to be deployed and scaled, end-to-end data pipelines to be created, and already is showcasing an extremely wide variety of functionality. But one particularly important use case has not been discussed as much. The Daisi platform itself is one of the best ways to deploy an API without any hassle or complication.

APIs are everywhere — they form the core data layer of a wide host of web applications, and allow users and programmers alike to access the data and information required to do their work and build their applications. The task of integrating with an API in an application has a number of fundamental challenges:

  1. APIs typically require authentication, or impose strict rate-limits on the number of calls that can be made.
  2. APIs across various services have widely different calling interfaces, making their integration into platforms challenging in general.
  3. APIs need to be deployed on some web-server in order to be accessible to the general public

Daisies alleviate each of these pain points, allowing anonymous access, a consistent and unified calling interface, and a central deployment solution that maintains the service for the lifetime of the application. We believe Daisies are the single easiest way to rapidly deploy an API.

API Deployment with Daisies

To illustrate this, let’s walk through three easy steps for doing so, using the NOAA Weather Daisi as our example.

Step 1: Define the Calling Interface

The first step is to define the calling interface, or the Python functions that will interact with the API. This can come in a number of ways, ranging from more low-level to more high-level:

  • We may define our own API from scratch, where we write functions which perform some computation that we expect developers and users to call. You may already have a number of these functions written, or some functionality may need to be abstracted to make the calling interface more user friendly.
  • We may directly access a pre-existing API using the requests library, or a similar library, which can make HTTP calls and process the results. If we wish to deploy some generalized, modified, or simplified version of an existing public API, this is the approach we may choose.
  • We may use a pre-existing Python package in order to interface with the API, to avoid the need for manual requests calls. This is the recommended approach if available, as work may have already been done to abstract the API into Python function calls that make development even easier

Because the noaa-sdk package is already available on PyPI, we chose the third option for our Daisi, to take advantage of the work that has already been done to abstract the API calls into easy-to-use Python functions. So what do we do? Very simple! We define as many functions as we want to expose functionality from the package in a simple Python script, like so:

Three simple functions abstract some functionality of the noaa-sdk package into Daisi-ready snippets

These simple transformations provide the Daisi the needed data. Let’s move on!

IMPORTANT NOTE: Often times, APIs will require some form of secret credentials. There are two key solutions for it:

  1. Secret credentials can be securely provided as input parameters to the Daisi itself, by passing them as arguments to functions that require them.
  2. Daisi code can seamlessly read from environment variable “secrets” stored within the Daisi, without exposing their values to the calling users. (This feature is in beta, to be released soon)

Step 2: Define the Daisi

This might be the simplest step of all — The Daisi Platform was produced under the idea that there should be a very minimal transition for a Python developer to deploy code as a Daisi. In fact, the functions as written above, form a valid Daisi! We simply:

  1. Create a GitHub repository with our functions inside of a script.
  2. (Optional) Define a README.md on GitHub with some information for your users about how to call the functions, and what your Daisi does.
  3. (Optional) Add docstrings to each function to help explain to your user their functionality, which will automatically show up as API documentation on the Daisi platform
  4. Create a new Daisi on app.daisi.io
  5. Choose your Repository and your Script
  6. Allow a few minutes for your Daisi to install and deploy
Deployed NOAA Weather Daisi on the app.daisi.io Platform

Once done, you now have a live API for your functions, accessible from anywhere. It’s that simple! If you want to go one step further, read on…

Step 3 (Optional): Add a Front End to Your Daisi

While the API provides developers with exactly what is needed to integrate your code into other applications and workflows, often times a User Interface is still an important component to help draw attention to your API. This is particularly useful for those that might be exploring the capabilities of it, and would prefer to do so via a point-and-click interface in their browser. Fortunately, this is also seamless and easy with Daisies!

Below, we define a user interface which calls those functions and renders them in a nice UI, automatically available on platform:

UI code for the NOAA Daisi

On platform, the Daisi will now display as an option a friendly user interface, like so:

Web UI for interacting with the NOAA Weather API Daisi

Conclusion

The ease of deploying an API using Daisies represents one of the most important use cases of the platform. We believe that this will drastically reduce the friction for developers to serve up code to other developers and users in hopes of creating interesting and relevant workflows. This NOAA Weather Daisi is a simple but very relevant example, and fits the paradigms of many use cases where Daisies can aid the development process.

For more information about Daisies, please see our articles Daisi — Python cloud functions for scientists and engineers and Create a Daisi — The fastest way to deploy any Python code (including a full app !). Full documentation is available at this link, and you can post in our community by clicking here.

Application Link

You can check out the NOAA WeatherDaisi here: https://app.daisi.io/daisies/4fab8b54-4919-4728-8d62-2318dc3457ab/info

--

--